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

Bump sys version #135

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Fix fuzzer
  • Loading branch information
Dr-Emann committed Jun 26, 2024
commit cdb125f7a5415478a4b20aa27cf6cd028ee90b66
36 changes: 15 additions & 21 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 44 additions & 3 deletions fuzz/fuzz_targets/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#![no_main]

use croaring::{Bitmap, Native, Portable};
use croaring::{Bitmap, Bitmap64, Native, Portable};
use libfuzzer_sys::fuzz_target;

fn check_bitmap<D: croaring::bitmap::Deserializer>(input: &[u8]) {
let bitmap = Bitmap::try_deserialize::<D>(input);
if let Some(mut bitmap) = bitmap {
bitmap.internal_validate().unwrap();

let unsafe_version = unsafe { D::try_deserialize_unchecked(input) };
assert_eq!(
bitmap,
unsafe_version,
"Unsafe doesn't match safe {}",
std::any::type_name::<D>()
);

let start_cardinality = bitmap.cardinality();
let mut new_cardinality = start_cardinality;
for i in 100..1000 {
Expand All @@ -16,14 +24,47 @@ fn check_bitmap<D: croaring::bitmap::Deserializer>(input: &[u8]) {
new_cardinality += 1;
}
}
assert_eq!(new_cardinality, bitmap.cardinality());
assert_eq!(
new_cardinality,
bitmap.cardinality(),
"Cardinality mismatch in {}",
std::any::type_name::<D>()
);
}
}

fn check_bitmap64<D: croaring::bitmap64::Deserializer>(input: &[u8]) {
let bitmap = Bitmap64::try_deserialize::<D>(input);
if let Some(mut bitmap) = bitmap {
bitmap.internal_validate().unwrap();

let unsafe_version = unsafe { D::try_deserialize_unchecked(input) };
assert_eq!(bitmap, unsafe_version);
assert_eq!(
bitmap,
unsafe_version,
"Unsafe doesn't match safe {}",
std::any::type_name::<D>()
);

let start_cardinality = bitmap.cardinality();
let mut new_cardinality = start_cardinality;
for i in 100..1000 {
if !bitmap.contains(i) {
bitmap.add(i);
new_cardinality += 1;
}
}
assert_eq!(
new_cardinality,
bitmap.cardinality(),
"Cardinality mismatch in {}",
std::any::type_name::<D>()
);
}
}

fuzz_target!(|input: &[u8]| {
check_bitmap::<Portable>(input);
check_bitmap::<Native>(input);
check_bitmap64::<Portable>(input);
});
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn check_serialized(lhs: &mut Bitmap, to_compare: &Bitmap, v: &mut Vec<u8>, inpu
v.clear();

let data = to_compare.serialize::<Portable>();
let data2 = to_compare.serialize_into::<Frozen>(v);
let data2 = to_compare.serialize_into_vec::<Frozen>(v);
let view1 = unsafe { BitmapView::deserialize::<Portable>(&data) };
assert_eq!(view1, *to_compare);
let view2 = unsafe { BitmapView::deserialize::<Frozen>(data2) };
Expand Down
Loading