Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential overflow in deserialization of Bitmap #271

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
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
Next Next commit
Fix potential overflow in deserialization of Bitmap
  • Loading branch information
kirk-baird committed Apr 8, 2024
commit 47eba81232cb9bf9289ce632a36d013cd41bc3f6
15 changes: 12 additions & 3 deletions src/bitmap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ impl RoaringBitmap {

let cardinality = intervals.iter().map(|[_, len]| *len as usize).sum();
let mut store = Store::with_capacity(cardinality);
intervals.into_iter().for_each(|[s, len]| {
store.insert_range(RangeInclusive::new(s, s + len));
});
intervals.into_iter().try_for_each(|[s, len]| -> Result<(), io::ErrorKind> {
let end = s.checked_add(len).ok_or(io::ErrorKind::InvalidData)?;
store.insert_range(RangeInclusive::new(s, end));
Ok(())
})?;
store
} else if cardinality <= ARRAY_LIMIT {
let mut values = vec![0; cardinality as usize];
Expand Down Expand Up @@ -267,4 +269,11 @@ mod test {
prop_assert_eq!(bitmap, RoaringBitmap::deserialize_from(buffer.as_slice()).unwrap());
}
}

#[test]
fn test_deserialize_overflow_s_plus_len() {
let data = vec![59, 48, 0, 0, 255, 130, 254, 59, 48, 2, 0, 41, 255, 255, 166, 197, 4, 0, 2];
let res = RoaringBitmap::deserialize_from(data.as_slice());
assert!(res.is_err());
}
}
Loading