Skip to content

Commit 6157daa

Browse files
committed
Return io::Error if failed to decode distance code width table
This resolves RazrFalcon/usvg#21
1 parent 258cf44 commit 6157daa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/deflate/symbol.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,14 @@ impl HuffmanCodec for DynamicHuffmanCodec {
399399
.or_else(|| literal_code_bitwidthes.last().cloned());
400400
distance_code_bitwidthes.extend(load_bitwidthes(reader, c, last)?);
401401
}
402-
debug_assert_eq!(distance_code_bitwidthes.len(), distance_code_count as usize);
402+
if distance_code_bitwidthes.len() > distance_code_count as usize {
403+
let message = format!(
404+
"The length of `distance_code_bitwidthes` is too large: actual={}, expected={}",
405+
distance_code_bitwidthes.len(),
406+
distance_code_count
407+
);
408+
return Err(io::Error::new(io::ErrorKind::InvalidData, message));
409+
}
403410

404411
Ok(Decoder {
405412
literal: huffman::DecoderBuilder::from_bitwidthes(

0 commit comments

Comments
 (0)