Skip to content

Commit 078b397

Browse files
committed
Fix integer overflow in BitBufferMut::truncate and append_n
Signed-off-by: Sungjin Kim <carp1230@gmail.com>
1 parent d257d09 commit 078b397

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

vortex-buffer/src/bit/buf_mut.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ impl BitBufferMut {
375375
if len > self.len {
376376
return;
377377
}
378-
378+
379+
assert!(self.offset <= usize::MAX - len, "Truncate on BitBufferMut overflowed");
379380
let end_bit = self.offset + len;
380381
let new_len_bytes = end_bit.div_ceil(8);
381382
self.buffer.truncate(new_len_bytes);
@@ -442,6 +443,8 @@ impl BitBufferMut {
442443
return;
443444
}
444445

446+
assert!(self.offset.checked_add(self.len).and_then(|v| v.checked_add(n)).is_some(),
447+
"Append on BitBufferMut overflowed");
445448
let end_bit_pos = self.offset + self.len + n;
446449
let required_bytes = end_bit_pos.div_ceil(8);
447450

0 commit comments

Comments
 (0)