From 0bbe433e917f4253df8536bf5e583b07f71bf6c0 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sun, 26 Apr 2020 14:14:31 +0200 Subject: [PATCH] core/io: fix reading escape bits past end in codebook --- nihav-core/src/io/codebook.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.39.5