Skip to content

Commit

Permalink
Increase limit for read_bits (#35)
Browse files Browse the repository at this point in the history
Distance codes can need up to 18 bits at once
  • Loading branch information
fintelia authored Dec 27, 2023
1 parent 84e5981 commit 0cfba34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lossless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ impl BitReader {
self.buf = buf;
}

pub(crate) fn read_bits<T: TryFrom<u16>>(&mut self, num: u8) -> Result<T, DecodingError> {
pub(crate) fn read_bits<T: TryFrom<u32>>(&mut self, num: u8) -> Result<T, DecodingError> {
debug_assert!(num as usize <= 8 * mem::size_of::<T>());
debug_assert!(num <= 16);
debug_assert!(num <= 32);

let mut value = 0;

Expand All @@ -651,7 +651,7 @@ impl BitReader {
return Err(DecodingError::BitStreamError);
}
let bit_true = self.buf[self.index] & (1 << self.bit_count) != 0;
value += u16::from(bit_true) << i;
value += u32::from(bit_true) << i;
self.bit_count = if self.bit_count == 7 {
self.index += 1;
0
Expand Down

0 comments on commit 0cfba34

Please sign in to comment.