Skip to content

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

Open
SAY-5 wants to merge 4 commits 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 4 commits into
jonhoo:mainfrom
SAY-5:fix-sample-count-overflow

Conversation

@SAY-5

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

Copy link
Copy Markdown

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.

jonhoo
jonhoo previously approved these changes Jul 5, 2026

@jonhoo jonhoo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! Would you mind also adding an entry to CHANGELOG.md?

@SAY-5

SAY-5 commented Jul 10, 2026

Copy link
Copy Markdown
Author

Added a CHANGELOG entry under Unreleased > Fixed.

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'

2 participants