fix: enforce ifd_value_size limits and detect PackBits under-decode
Two input validation fixes: - vec_with_capacity now checks raw IFD value bytes against ifd_value_size before allocating. Previously only the in-memory Value representation was bounded (by decoding_buffer_size), so a crafted IFD with a large count of small-typed values could allocate based on raw byte count without limit checking. Also fix ASCII value parsing to check ifd_value_size instead of decoding_buffer_size. - LogLuv PackBits decoder now verifies that the expected number of pixels was actually decoded per plane, returning UnexpectedEof if the RLE stream ends short.
This commit is contained in:
1 parent
6a3282e9f2
commit
e4c3c1fcfd
2 files changed
+34
-16
No files matched your search
@@ -87,6 +87,7 @@ fn packbits_decode<R: Read, const N: usize>(
|
||||
reader: &mut R,
|
||||
buf: &mut [[u8; N]],
|
||||
) -> std::io::Result<()> {
|
||||
let expected = buf.len();
|
||||
for offset in (0..N).rev() {
|
||||
let mut i = 0;
|
||||
let mut code = [0u8; 1];
|
||||
@@ -124,6 +125,13 @@ fn packbits_decode<R: Read, const N: usize>(
|
||||
i += usize::from(repeat);
|
||||
}
|
||||
}
|
||||
|
||||
if i < expected {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
"PackBits RLE decoded fewer pixels than expected",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user