Skip to content

fix: avoid integer overflow when computing percentage for large sample counts#367

Open
SAY-5 wants to merge 1 commit into
jonhoo:mainfrom
SAY-5:fix-sample-count-overflow
Open

fix: avoid integer overflow when computing percentage for large sample counts#367
SAY-5 wants to merge 1 commit into
jonhoo:mainfrom
SAY-5:fix-sample-count-overflow

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 24, 2026

Fixes #170.

When a stack has a very large sample count (e.g. offwaketime output with values around 2.4e17), 100 * samples overflowed the integer type and panicked with "attempt to multiply with overflow" at src/flamegraph/mod.rs. The same applied to 100 * delta in the differential path.

Performing the * 100 in floating point (100.0 * x as f64) avoids the overflow. Output is unchanged for normal-magnitude inputs.

Added a regression test that feeds large sample counts through from_lines and asserts it does not panic.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"offwaketime" output causes 'attempt to multiply with overflow'

1 participant