Skip to content

Commit

Permalink
Check for round trips (BinaryHeap isn't PartialEq)
Browse files Browse the repository at this point in the history
  • Loading branch information
5225225 committed Jan 8, 2022
1 parent 5a94dfc commit a1dec47
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use std::net::*;
use std::path::*;
use std::time::*;

#[derive(bincode::Decode)]
#[derive(bincode::Decode, bincode::Encode, PartialEq, Debug)]
enum AllTypes {
BinaryHeap(BinaryHeap<u8>),
BTreeMap(BTreeMap<u8, u8>),
HashMap(HashMap<u8, u8>),
BTreeSet(BTreeSet<u8>),
Expand Down Expand Up @@ -42,8 +41,15 @@ enum AllTypes {
}

fuzz_target!(|data: &[u8]| {
let config = bincode::config::Configuration::standard().with_limit::<1024>();
let result: Result<(AllTypes, _), _> = bincode::decode_from_slice(
data,
bincode::config::Configuration::standard().with_limit::<1024>(),
config,
);

if let Ok((before, _)) = result {
let encoded = bincode::encode_to_vec(&before, config).expect("round trip");
let (after, _) = bincode::decode_from_slice(&encoded, config).unwrap();
assert_eq!(before, after);
}
});

0 comments on commit a1dec47

Please sign in to comment.