From 385258b6e72414869796e56b38f1d11776ef150c Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 13 Oct 2022 18:21:33 +0200 Subject: [PATCH] core/io: allow skipping right to the bitstream end --- nihav-core/src/io/bitreader.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nihav-core/src/io/bitreader.rs b/nihav-core/src/io/bitreader.rs index 569330b..c4f9f6c 100644 --- a/nihav-core/src/io/bitreader.rs +++ b/nihav-core/src/io/bitreader.rs @@ -305,8 +305,11 @@ impl<'a> BitReader<'a> { self.reset_cache(); self.pos += ((skip_bits / 32) * 4) as usize; skip_bits &= 0x1F; - self.refill()?; if skip_bits > 0 { + self.refill()?; + if u32::from(self.bits) < skip_bits { + return Err(BitstreamEnd); + } self.skip_cache(skip_bits as u8); } Ok(()) -- 2.39.5