Skip to content

Commit

Permalink
Made the compat fuzzer ignore any LimitExceeded error (#515)
Browse files Browse the repository at this point in the history
* Made the compat fuzzer ignore any LimitExceeded error

* Switched from deserialize to deserialize_from

Co-authored-by: Victor Koenders <git@trangar.com>
  • Loading branch information
VictorKoenders and Victor Koenders committed Mar 3, 2022
1 parent 7e9f043 commit 1b5c2ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
16 changes: 8 additions & 8 deletions fuzz/Cargo.lock

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

24 changes: 18 additions & 6 deletions fuzz/fuzz_targets/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,25 @@ fuzz_target!(|data: &[u8]| {
#[allow(deprecated)]
let mut configv1 = bincodev1::config();
configv1.limit(1024);
let bincode_v1: Result<AllTypes, _> = configv1.deserialize(data);
let bincode_v1: Result<AllTypes, _> = configv1.deserialize_from(data);
let bincode_v2: Result<(AllTypes, _), _> = bincode::decode_from_slice(data, config);

if bincode_v1.as_ref().ok() != bincode_v2.as_ref().ok().map(|x| &x.0) {
println!("Bytes: {:?}", data);
println!("Bincode V1: {:?}", bincode_v1);
println!("Bincode V2: {:?}", bincode_v2);
panic!("failed equality check");
match (&bincode_v1, &bincode_v2) {
(Err(e), _) if e.to_string() == "the size limit has been reached" => {},
(_, Err(bincode::error::DecodeError::LimitExceeded)) => {},
(Ok(bincode_v1), Ok((bincode_v2, _))) if bincode_v1 != bincode_v2 => {
println!("Bytes: {:?}", data);
println!("Bincode V1: {:?}", bincode_v1);
println!("Bincode V2: {:?}", bincode_v2);
panic!("failed equality check");
},
(Ok(_), Err(_)) | (Err(_), Ok(_)) => {
println!("Bytes: {:?}", data);
println!("Bincode V1: {:?}", bincode_v1);
println!("Bincode V2: {:?}", bincode_v2);
panic!("failed equality check");
}

_ => {}
}
});

0 comments on commit 1b5c2ab

Please sign in to comment.