Skip to content

Commit a1dec47

Browse files
committed
Check for round trips (BinaryHeap isn't PartialEq)
1 parent 5a94dfc commit a1dec47

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fuzz/fuzz_targets/fuzz_target_1.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use std::net::*;
1111
use std::path::*;
1212
use std::time::*;
1313

14-
#[derive(bincode::Decode)]
14+
#[derive(bincode::Decode, bincode::Encode, PartialEq, Debug)]
1515
enum AllTypes {
16-
BinaryHeap(BinaryHeap<u8>),
1716
BTreeMap(BTreeMap<u8, u8>),
1817
HashMap(HashMap<u8, u8>),
1918
BTreeSet(BTreeSet<u8>),
@@ -42,8 +41,15 @@ enum AllTypes {
4241
}
4342

4443
fuzz_target!(|data: &[u8]| {
44+
let config = bincode::config::Configuration::standard().with_limit::<1024>();
4545
let result: Result<(AllTypes, _), _> = bincode::decode_from_slice(
4646
data,
47-
bincode::config::Configuration::standard().with_limit::<1024>(),
47+
config,
4848
);
49+
50+
if let Ok((before, _)) = result {
51+
let encoded = bincode::encode_to_vec(&before, config).expect("round trip");
52+
let (after, _) = bincode::decode_from_slice(&encoded, config).unwrap();
53+
assert_eq!(before, after);
54+
}
4955
});

0 commit comments

Comments
 (0)