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

Commit

Permalink
Fixed panic in bitmap assign_mut (#1078)
Browse files Browse the repository at this point in the history
* fix oob access in bitmap assign

* undo changes and fix root cause
  • Loading branch information
ritchie46 authored Jun 16, 2022
1 parent 2e10f4e commit cd20ddf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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()
} 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

0 comments on commit cd20ddf

Please sign in to comment.