From: Kostya Shishkov Date: Sun, 26 Apr 2020 12:14:31 +0000 (+0200) Subject: core/io: fix reading escape bits past end in codebook X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=0bbe433e917f4253df8536bf5e583b07f71bf6c0;p=nihav.git core/io: fix reading escape bits past end in codebook --- diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 553f2f9..d835ce3 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -370,10 +370,10 @@ impl<'a, S: Copy> CodebookReader for BitReader<'a> { let bits = cb.table[lut_idx] & 0x7F; esc = (cb.table[lut_idx] & 0x80) != 0; idx = (cb.table[lut_idx] >> 8) as usize; - if (bits as isize) > self.left() { + let skip_bits = if esc { u32::from(lut_bits) } else { bits }; + if (skip_bits as isize) > self.left() { return Err(CodebookError::InvalidCode); } - let skip_bits = if esc { u32::from(lut_bits) } else { bits }; self.skip(skip_bits as u32).unwrap(); lut_bits = bits as u8; }