-
Notifications
You must be signed in to change notification settings - Fork 59
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
fix: don't panic on non minimal varints #293
Conversation
If a varint it non-minimally encoded in a no_std environment, don't panic, but return an error. Also some minor Clippy warnings were fixed. Fixes #282.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick response.
#[test] | ||
fn decode_non_minimal_error() { | ||
// This is a non-minimal varint. | ||
let data = [241, 0, 0, 0, 0, 0, 128, 132, 132, 132, 58]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just another data point, here's the data that we found from fuzz testing that caused the panic:
let data = [0, 1, 0, 1, 203, 155, 0, 0, 0, 5, 67];
return decode::u64(&b[..=i]) | ||
.map(|decoded| decoded.0) | ||
.map_err(Error::Varint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this change with our project and it fixes the panic, Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my limited knowledge of rust-multihash
, this looks good to me.
If a varint it non-minimally encoded in a no_std environment, don't panic, but return an error.
Also some minor Clippy warnings were fixed.
Fixes #282.