Skip to content

Commit

Permalink
Fix LEB128-related panic again (#2337)
Browse files Browse the repository at this point in the history
* Fix LEB128-related panic again

* Update CHANGELOG

* Rustfmt
  • Loading branch information
tomaka authored Jun 7, 2022
1 parent 96bd6d1 commit f2748c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
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

0 comments on commit f2748c2

Please sign in to comment.