Skip to content

Commit

Permalink
feat(fuzz): fuzz deserialize better
Browse files Browse the repository at this point in the history
The fuzzer will do a better job finding interesing inputs if we make the type
of deserization a branch rather than always trying all types for every input.
  • Loading branch information
Dr-Emann committed Sep 19, 2024
1 parent 5c85403 commit 4bab7ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

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

19 changes: 15 additions & 4 deletions fuzz/fuzz_targets/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

fn check_bitmap<D: croaring::bitmap::Deserializer>(input: &[u8]) {
let bitmap = Bitmap::try_deserialize::<D>(input);
Expand Down Expand Up @@ -63,8 +64,18 @@ fn check_bitmap64<D: croaring::bitmap64::Deserializer>(input: &[u8]) {
}
}

fuzz_target!(|input: &[u8]| {
check_bitmap::<Portable>(input);
check_bitmap::<Native>(input);
check_bitmap64::<Portable>(input);
#[derive(Arbitrary, Debug)]
enum BitmapType {
Portable32,
Native32,
Portable64,
}

fuzz_target!(|input: (BitmapType, &[u8])| {
let (ty, input) = input;
match ty {
BitmapType::Portable32 => check_bitmap::<Portable>(input),
BitmapType::Native32 => check_bitmap::<Native>(input),
BitmapType::Portable64 => check_bitmap64::<Portable>(input),
}
});

0 comments on commit 4bab7ec

Please sign in to comment.