Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flamegraph panics on empty lines with --reverse set #238

Closed
mrob95 opened this issue May 1, 2022 · 0 comments · Fixed by #239
Closed

flamegraph panics on empty lines with --reverse set #238

mrob95 opened this issue May 1, 2022 · 0 comments · Fixed by #239

Comments

@mrob95
Copy link
Contributor

mrob95 commented May 1, 2022

Found while I was investigating #237

Repro:

  • Change tests/data/flamegraph/bad-lines/bad-lines.txt to the following (adding a blank line):
cksum;_start;__libc_start_main;main;cksum 31
cksum;cksum 6
THIS IS A BAD LINE
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1
cksum;main;cksum 19
THIS IS A BAD FRACTIONAL LINE 12V.43
noploop;[unknown] 2
noploop;main 274

noploop;[unknown] 2
  • Run cargo test flamegraph_should_warn_about_bad_input_lines_with_reversed_stack_ordering

Failure:

---- flamegraph_should_warn_about_bad_input_lines_with_reversed_stack_ordering stdout ----
thread 'flamegraph_should_warn_about_bad_input_lines_with_reversed_stack_ordering' panicked at 'attempt to subtract with overflow', /home/mike/inferno/src/flamegraph/mod.rs:415:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    flamegraph_should_warn_about_bad_input_lines_with_reversed_stack_ordering

The issue is here: https://github.com/jonhoo/inferno/blob/master/src/flamegraph/mod.rs#L411

samples_idx is 0 when we have an empty line, and we are trying to subtract from it.

A simple fix would be to add a check for line.is_empty() at the top of that loop. Alternatively, it seems like the reason we are subtracting 1 from sample_idx is to remove a trailing space from the line, so replacing with &line[..samples_idx].trim_end() would fix it.

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 a pull request may close this issue.

1 participant