Copilot commented on code in PR #582:
URL: https://github.com/apache/avro-rs/pull/582#discussion_r3566842461


##########
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:
   `Codec::Snappy` slices use `stream.len() - 4`. If the input block is 
truncated/corrupt and shorter than 4 bytes (missing the CRC), this will 
underflow and the subsequent slice/copy will panic (process abort / DoS). Use a 
safe `data_end = stream.len().saturating_sub(4)` (or `checked_sub`) and slice 
via `..data_end` / `data_end..` so short inputs return a normal `AvroResult` 
error instead of panicking.



-- 
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]

Reply via email to