Skip to content

Commit

Permalink
merge the fuzzers into one
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Jan 31, 2025
1 parent eb9f678 commit 62c4a82
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions fuzz/fuzz_targets/deserialize_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,16 @@ fuzz_target!(|data: &[u8]| {
let b1 = node_to_bytes_backrefs(&allocator, program).unwrap();

let mut allocator = Allocator::new();
let cp = allocator.checkpoint();
let program = node_from_bytes_backrefs(&mut allocator, &b1).unwrap();
let new_pair_count = allocator.pair_count();
allocator.restore_checkpoint(&cp);
let program_old = node_from_bytes_backrefs_old(&mut allocator, &b1).unwrap();
// check we aren't making more nodes in the new version
assert!(new_pair_count <= allocator.pair_count());
// check that the two versions of the deserializer produce the same/correct result
let b2 = node_to_bytes_backrefs(&allocator, program).unwrap();
assert_eq!(b1, b2);
let b3 = node_to_bytes_backrefs(&allocator, program_old).unwrap();
assert_eq!(b1, b3);
});

// #[cfg(feature = "counters")]
fuzz_target!(|data: &[u8]| {
let mut allocator = Allocator::new();
let cp = allocator.checkpoint();
let program = match node_from_bytes_backrefs(&mut allocator, data) {
Err(_) => {
return;
}
Ok(r) => r,
};

let b1 = node_to_bytes_backrefs(&allocator, program).unwrap();

// reset allocators
allocator.restore_checkpoint(&cp);

let _program = node_from_bytes_backrefs(&mut allocator, &b1).unwrap();
let new_pair_count = allocator.pair_count();
allocator.restore_checkpoint(&cp);
let _program_old = node_from_bytes_backrefs_old(&mut allocator, &b1).unwrap();
assert!(new_pair_count <= allocator.pair_count());
});

0 comments on commit 62c4a82

Please sign in to comment.