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

Arithmetic overflow occurs while using API LineRange::from() #2674

Closed
HeeillWang opened this issue Sep 22, 2023 · 2 comments · Fixed by #2698
Closed

Arithmetic overflow occurs while using API LineRange::from() #2674

HeeillWang opened this issue Sep 22, 2023 · 2 comments · Fixed by #2698
Labels
bug Something isn't working

Comments

@HeeillWang
Copy link

What steps will reproduce the bug?
I executed fuzz testing with bat public APIs and found crash case.

let fuzz_arg1 = "18446744073709551615:+1";
LineRange::from(fuzz_arg1);

What happens?

Thread '<unnamed>' panicked at 'attempt to add with overflow', /rustc/871b5952023139738f72eba235063575062bc2e9/library/core/src/ops/arith.rs:109

The overflow occurs with this statement :

new_range.lower + more_lines

What did you expect to happen instead?
Need assertion to prevent arith overflow, or need to explicitly mention panic condition.

@HeeillWang HeeillWang added the bug Something isn't working label Sep 22, 2023
@sohang3112
Copy link

Maybe saturating_add(new_range.lower, more_lines) can be done here to avoid panicking.

@HeeillWang
Copy link
Author

Maybe saturating_add(new_range.lower, more_lines) can be done here to avoid panicking.

Looks nice, better than assert!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants