Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions arrow-buffer/src/util/bit_chunk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,8 @@ pub struct BitChunks<'a> {
impl<'a> BitChunks<'a> {
/// Create a new [`BitChunks`] from a byte array, and an offset and length in bits
pub fn new(buffer: &'a [u8], offset: usize, len: usize) -> Self {
assert!(
ceil(offset + len, 8) <= buffer.len(),
"offset + len out of bounds"
);
let end = offset.checked_add(len).expect("offset + len out of bounds");
assert!(ceil(end, 8) <= buffer.len(), "offset + len out of bounds");

let byte_offset = offset / 8;
let bit_offset = offset % 8;
Expand Down Expand Up @@ -550,6 +548,13 @@ mod tests {
buffer.bit_chunks(1, ALLOC_SIZE * 8);
}

#[test]
#[should_panic(expected = "offset + len out of bounds")]
fn test_out_of_bound_should_panic_when_offset_and_length_overflow() {
let buffer = Buffer::from(vec![0xFF_u8; 8]);
buffer.bit_chunks(1, usize::MAX);
}

#[test]
#[allow(clippy::assertions_on_constants)]
fn test_unaligned_bit_chunk_iterator() {
Expand Down
Loading