-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
FrameDecoder panics on malformed input #29
Comments
Definitely looks like a bug. Also looks like the bug is here too: Line 170 in 1951d5d
Either checked subtraction or just adding an explicit |
Sure, no worries. Lines 156 to 165 in 1951d5d
but the docs for this variant says Maybe this requires a new error variant along the lines of |
Ug. I meant to make the enum non-exhaustive when I did the 1.0 release. So that means adding a new variant is a breaking change.
|
Sorry, didn't think of this.
This sounds great. Will do this. |
Got the same panic today: use snap::read;
use std::io::Read;
fn main() {
let data: &[u8] = &[0x10, 0x10, 0x0, 0x0];
let mut buf = vec![];
read::FrameDecoder::new(data).read_to_end(&mut buf).unwrap();
} # ./target/release/testing
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom
{ kind: Other, error: StreamHeader { byte: 16 } }', src/libcore/result.rs:11$
8:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace$ found it with the help of https://github.com/rust-fuzz/cargo-fuzz |
@flipchan That's not the same panic. And it's not even clear that it's a bug. You're calling |
Previously, the code was assuming that we could always subtract 4 from the length, but the length is untrusted data. If an invalid length is detected, we return an error instead. Closes #29
Fixes GHSA-wjxc-pjx9-4wvm CKB process will panic when received malformed p2p message BurntSushi/rust-snappy#29
Encountered a panic
thread 'main' panicked at 'attempt to subtract with overflow',
while decoding malformed input bytes.The panic occurred here
rust-snappy/src/read.rs
Line 191 in 1951d5d
The malformed input after providing the correct stream identifier chunk has 4 zero bytes which leads to
len
becoming 0 and hence panics when we try to do unsafe subtraction in line 191.The stack trace:
I think we can fix this by doing checked subtraction and returning an error if there's an underflow.
Will be happy to raise a PR if you can confirm it's an issue :)
The text was updated successfully, but these errors were encountered: