Skip to content

Conversation

@vmx
Copy link
Member

@vmx vmx commented Apr 13, 2023

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.

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.
@vmx vmx requested a review from mxinden April 13, 2023 09:09
Copy link

@mattheworris mattheworris left a 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];

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];

Comment on lines +366 to +368
return decode::u64(&b[..=i])
.map(|decoded| decoded.0)
.map_err(Error::Varint);

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!

Copy link
Member

@mxinden mxinden left a 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.

@vmx vmx merged commit c3445fc into release/v0.18.x Apr 14, 2023
@vmx vmx deleted the decode-overflow-backport branch April 14, 2023 16:36
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.

5 participants