mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 08:34:07 +02:00
fix read_bool being able to set stream position outside bounds when using sub streams
This commit is contained in:
parent
77fbba7e5b
commit
a6d9931641
1 changed files with 7 additions and 7 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue