Skip to content

Mermaid pie legend: extreme values round wrong via f64->i64 cast #12

Closed

Description

@jjbaumert

Summary: trim_num in crates/mermaid/src/pie.rs:184-190 casts an f64 legend value to i64 when the fractional part is zero. For values at or above 2^63 (~9.22 quintillion) with zero fract, the cast saturates and the legend displays 9223372036854775807 instead of the actual (much larger) value.

Severity: S4 — latent/internal. No panic, no data corruption, and a pie-chart value of ≥2^63 is an extreme, unlikely-in-practice input, but it is a genuine silent-wrong-display defect rather than a graceful rejection or clamp-with-warning.

Environment:

  • Deploy: any (pure function, no environment dependency)
  • Commit: 6411ddb

Repro steps:

  1. Call trim_num(9223372036854775808.0) (i.e. 2f64.powi(63), which has zero fractional part).
  2. Observe the returned string.

Expected: Either a value that round-trips reasonably close to the input, or an explicit "value too large to display precisely" fallback.

Observed: Displays 9223372036854775807 (i64::MAX), silently wrong by construction of the as i64 saturating cast.

Evidence:

  • Code: crates/mermaid/src/pie.rs:184-190 (trim_num), the v as i64 cast on the zero-fract branch.
  • Existing test trim_num_formats_whole_and_fractional_values (crates/mermaid/src/pie.rs:378-381) only covers small/ordinary values (7.0, 0.0, 1.5), not the overflow boundary.

Suspected area: crates/mermaid/src/pie.rs::trim_num — needs a saturating-cast-aware guard or a different formatting strategy for values outside i64's exact range.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingverification-findingFinding from a verification run

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions