1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-04 00:54:07 +02:00

fix read_bool being able to set stream position outside bounds when using sub streams

This commit is contained in:
Robin Appelman 2020-01-19 21:12:17 +01:00
commit a6d9931641

View file

@ -158,16 +158,16 @@ where
let byte_index = position / 8;
let bit_offset = position & 7;
self.bytes
.get(byte_index)
.ok_or_else(|| ReadError::NotEnoughData {
if position < self.bit_len() {
let byte = self.bytes[byte_index];
let shifted = byte >> bit_offset;
Ok(shifted & 1u8 == 1)
} else {
Err(ReadError::NotEnoughData {
requested: 1,
bits_left: self.bit_len().saturating_sub(position),
})
.map(|byte| {
let shifted = byte >> bit_offset;
shifted & 1u8 == 1
})
}
}
#[doc(hidden)]