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

Fix LEB128-related panic again #2337

Merged
merged 4 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed

- Fix another panic in case of a carefully-crafted LEB128 length. ([#2337](https://github.com/paritytech/smoldot/pull/2337))
- Fix a panic when decoding a block header containing a large number of Aura authorities. ([#2338](https://github.com/paritytech/smoldot/pull/2338))
- Fix multiple panics when decoding network messages in case where these messages were truncated. ([#2340](https://github.com/paritytech/smoldot/pull/2340))

Expand Down
4 changes: 4 additions & 0 deletions src/util/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ impl FramedInProgress {
let mut out = 0usize;

for (n, byte) in buffer.iter().enumerate() {
if (7 * n) >= usize::try_from(usize::BITS).unwrap() {
return Some(Err(FramedError::LengthPrefixTooLarge));
}

match usize::from(*byte & 0b111_1111).checked_mul(1 << (7 * n)) {
Some(o) => out |= o,
None => return Some(Err(FramedError::LengthPrefixTooLarge)),
Expand Down