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 panic in FrameDecoder #30

Merged
merged 1 commit into from
Jul 6, 2020
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
5 changes: 2 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ pub enum Error {
/// The chunk type byte that was read.
byte: u8,
},
/// This error occurs when trying to read a chunk with length greater than
/// that supported by this library when reading a Snappy frame formatted
/// stream.
/// This error occurs when trying to read a chunk with an unexpected or
/// incorrect length when reading a Snappy frame formatted stream.
/// This error only occurs when reading a Snappy frame formatted stream.
UnsupportedChunkLength {
/// The length of the chunk encountered.
Expand Down
12 changes: 12 additions & 0 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ impl<R: io::Read> io::Read for FrameDecoder<R> {
}
}
Ok(ChunkType::Uncompressed) => {
if len < 4 {
fail!(Error::UnsupportedChunkLength {
len: len as u64,
header: false,
});
}
let expected_sum = bytes::io_read_u32_le(&mut self.r)?;
let n = len - 4;
if n > self.dst.len() {
Expand All @@ -187,6 +193,12 @@ impl<R: io::Read> io::Read for FrameDecoder<R> {
self.dste = n;
}
Ok(ChunkType::Compressed) => {
if len < 4 {
fail!(Error::UnsupportedChunkLength {
len: len as u64,
header: false,
});
}
let expected_sum = bytes::io_read_u32_le(&mut self.r)?;
let sn = len - 4;
if sn > self.src.len() {
Expand Down