short circuit zero-length huffman codes

This commit is contained in:
Jessa 2023-10-12 23:05:36 -07:00
parent 087583a5fe
commit 2aa034456c
2 changed files with 12 additions and 1 deletions

View File

@ -801,4 +801,10 @@ mod test {
assert_matches!(err.get_ref(), ParseError::InvalidChunkLayout, "{err:?}");
});
}
#[test]
pub fn lossless_max_image_data() {
let data = b"\x2f\xff\xff\xff\x0f\x81\x88\x88\x18\x44\x44\xc4\xff\x45\x44\x04\x21\x22\x22\x22\x22\x02";
test_webp().image_data(&data[..]).build().sanitize_ok();
}
}

View File

@ -316,6 +316,7 @@ impl EntropyCodedImage {
) -> Result<Self, Error> {
let color_cache = ColorCache::read(reader).await.while_parsing_type()?;
let codes = PrefixCodeGroup::read(reader, &color_cache).await.while_parsing_type()?;
let argb_readahead_bits = codes.argb_readahead_bits();
let readahead_bits = codes.readahead_bits();
let len = width.saturating_mul(height);
@ -329,7 +330,11 @@ impl EntropyCodedImage {
let color = Color::buf_read(reader, symbol as u8, &codes).while_parsing_type()?;
log::debug!("color: {color}");
fun(color)?;
pixel_idx += 1;
if argb_readahead_bits == 0 {
pixel_idx = len.get();
} else {
pixel_idx += 1;
}
}
symbol @ 256..=279 => {
let back_ref = BackReference::buf_read(reader, symbol - 256, &codes, width).while_parsing_type()?;