core/io: allow skipping right to the bitstream end
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 13 Oct 2022 16:21:33 +0000 (18:21 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 13 Oct 2022 16:22:10 +0000 (18:22 +0200)
nihav-core/src/io/bitreader.rs

index 569330b5be59e14ab75612c14462ba18832dec0a..c4f9f6c8a3490edeccb1ed4385e495f15ee940a7 100644 (file)
@@ -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(())