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

FixedLenByteArray max_precision integer overflow #184

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

evanrichter
Copy link
Contributor

fuzzing found a multiplication overflow here:

(2f64.powi(8 * (*length as i32) - 1) - 1f64).log10().floor() as usize;

so I changed it to a checked_mul and also realized the subtract 1 could underflow also. the fuzzer didn't confirm, but the rust compiler did:

error: this arithmetic operation will overflow
 --> src/main.rs:2:20
  |
2 |     println!("{}", (i32::MIN / 8) * 8 - 1);
  |                    ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i32::MIN - 1_i32`, which would overflow

@jorgecarleitao jorgecarleitao added the bug Something isn't working label Aug 16, 2022
@jorgecarleitao jorgecarleitao merged commit 73fefd2 into jorgecarleitao:main Aug 16, 2022
@jorgecarleitao
Copy link
Owner

Thanks, @evanrichter 🙇

@evanrichter evanrichter deleted the fix-mult-overflow branch August 16, 2022 17:15
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 this pull request may close these issues.

2 participants