Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Fixed panic in bitmap assign_mut #1078

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ impl Bitmap {
pub fn make_mut(self) -> MutableBitmap {
match self.into_mut() {
Either::Left(data) => {
MutableBitmap::from_vec(data.bytes.as_ref().to_vec(), data.length)
if data.offset > 0 {
// we have to recreate the bytes because a MutableBitmap does not have an `offset`.
data.iter().collect()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can improve this further by using iter_chunk, which will iterate in chunks of u64. We have a function somewhere to create a MutableBitmap from chunks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but that seems to not include the remainder

                 let chunks = BitChunks::<u64>::new(data.bytes.as_ref(), data.offset, data.length);
                    chunk_iter_to_vec(chunks)

} else {
MutableBitmap::from_vec(data.bytes.as_ref().to_vec(), data.length)
}
}
Either::Right(data) => data,
}
Expand Down
18 changes: 18 additions & 0 deletions tests/it/bitmap/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ fn basics() {
);
}

#[test]
fn binary_assign_oob() {
// this check we don't have an oob access if the bitmaps are size T + 1
// and we do some slicing.
let a = MutableBitmap::from_iter(std::iter::repeat(true).take(65));
let b = MutableBitmap::from_iter(std::iter::repeat(true).take(65));

let a: Bitmap = a.into();
let a = a.slice(10, 20);

let b: Bitmap = b.into();
let b = b.slice(10, 20);

let mut a = a.make_mut();

binary_assign(&mut a, &b, |x: u64, y| x & y);
}

#[test]
fn fast_paths() {
let b = MutableBitmap::from([true, false]);
Expand Down