mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
fix reading bool from sub-stream causing position to get out of sub-stream bounds
This commit is contained in:
parent
587d4ac8ef
commit
8bc758c237
3 changed files with 10 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bitbuffer"
|
||||
version = "0.10.8"
|
||||
version = "0.10.9"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2021"
|
||||
description = "Reading bit sequences from a byte slice"
|
||||
|
|
|
|||
|
|
@ -291,6 +291,13 @@ where
|
|||
let byte_index = position / 8;
|
||||
let bit_offset = position & 7;
|
||||
|
||||
// `slice` isn't limited by any sub-buffer size, so we need to manually check
|
||||
if position >= self.bit_len() {
|
||||
return Err(BitError::NotEnoughData {
|
||||
requested: 1,
|
||||
bits_left: 0,
|
||||
});
|
||||
}
|
||||
if let Some(byte) = self.slice.get(byte_index) {
|
||||
if E::is_le() {
|
||||
let shifted = byte >> bit_offset as u8;
|
||||
|
|
|
|||
|
|
@ -314,6 +314,7 @@ where
|
|||
Some(len) => len * 8,
|
||||
None => min((*len + 1) * 8, max_length * 8),
|
||||
};
|
||||
|
||||
*len = (*len).min(max_length);
|
||||
}
|
||||
err
|
||||
|
|
@ -328,7 +329,7 @@ where
|
|||
// thus we trim the resulting string to make sure it fits in the source stream
|
||||
if read > self.bits_left() {
|
||||
// find the maximum well-formed utf8 string that fits in max_len
|
||||
let mut acc = String::new();
|
||||
let mut acc = String::with_capacity(max_length);
|
||||
for c in result.chars() {
|
||||
if acc.len() + c.len_utf8() > max_length {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue