iemejia commented on code in PR #582:
URL: https://github.com/apache/avro-rs/pull/582#discussion_r3566848991
##########
avro/src/codec.rs:
##########
@@ -167,6 +180,9 @@ impl Codec {
Codec::Snappy => {
let decompressed_size =
snap::raw::decompress_len(&stream[..stream.len() - 4])
.map_err(Details::GetSnappyDecompressLen)?;
+ // The decompressed size is taken from the (untrusted) block
+ // header, so bound it before allocating for it.
+ let decompressed_size =
crate::util::safe_len(decompressed_size)?;
Review Comment:
Fixed in ea34450: a Snappy block shorter than the trailing 4-byte CRC now
computes `data_end = stream.len().checked_sub(4)` and returns a new
(snappy-gated) `Details::BadSnappyLength` error, slicing via the checked offset
— so a short/corrupt block returns an `AvroResult` error instead of
underflowing `stream.len() - 4` and panicking. Added a regression test over
0..4-byte inputs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]