Skip to content

Commit

Permalink
Return io::Error if failed to decode distance code width table
Browse files Browse the repository at this point in the history
This resolves RazrFalcon/usvg#21
  • Loading branch information
sile committed Jul 1, 2018
1 parent 258cf44 commit 6157daa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/deflate/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,14 @@ impl HuffmanCodec for DynamicHuffmanCodec {
.or_else(|| literal_code_bitwidthes.last().cloned());
distance_code_bitwidthes.extend(load_bitwidthes(reader, c, last)?);
}
debug_assert_eq!(distance_code_bitwidthes.len(), distance_code_count as usize);
if distance_code_bitwidthes.len() > distance_code_count as usize {
let message = format!(
"The length of `distance_code_bitwidthes` is too large: actual={}, expected={}",
distance_code_bitwidthes.len(),
distance_code_count
);
return Err(io::Error::new(io::ErrorKind::InvalidData, message));
}

Ok(Decoder {
literal: huffman::DecoderBuilder::from_bitwidthes(
Expand Down

0 comments on commit 6157daa

Please sign in to comment.