Skip to content

Commit 141d008

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

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

vortex-buffer/src/bit/buf_mut.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ impl BitBufferMut {
376376
return;
377377
}
378378

379-
let end_bit = self.offset + len;
379+
let end_bit = self.offset.checked_add(len)
380+
.expect("BitBufferMut::truncate: offset + len overflow");
380381
let new_len_bytes = end_bit.div_ceil(8);
381382
self.buffer.truncate(new_len_bytes);
382383
self.len = len;
@@ -442,7 +443,9 @@ impl BitBufferMut {
442443
return;
443444
}
444445

445-
let end_bit_pos = self.offset + self.len + n;
446+
let end_bit_pos = self.offset.checked_add(self.len)
447+
.and_then(|v| v.checked_add(n))
448+
.expect("BitBufferMut::append_n: offset + len + n overflow");
446449
let required_bytes = end_bit_pos.div_ceil(8);
447450

448451
// Ensure buffer has enough bytes

0 commit comments

Comments
 (0)