Fuzz for compatibility with bincode v1 (#498)
* Fuzz for compatibility with bincode v1 * Make AllTypes recursive * Revert round trip test (add recursion to it too) * Update fuzzer lockfile * Adjust compat fuzzer to be stricter * data doesn't need to be a &&[u8]
This commit is contained in:
parent
cbad043a53
commit
da94b7aaf9
|
|
@ -8,6 +8,15 @@ version = "1.0.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "510c76ecefdceada737ea728f4f9a84bd2e1ef29f1ba555e560940fe279954de"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "2.0.0-beta.2"
|
||||
|
|
@ -19,8 +28,10 @@ dependencies = [
|
|||
name = "bincode-fuzz"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bincode 1.3.3",
|
||||
"bincode 2.0.0-beta.2",
|
||||
"libfuzzer-sys",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -54,7 +65,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.4"
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0e85ed1066abcc0ea331cce3ce83cccf30ae9900529ca46f353b22ca79b56b8"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.135"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cf9235533494ea2ddcdb794665461814781c53f19d87b76e571a1c35acbad2b"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.135"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dcde03d87d4c973c04be249e7d8f0b35db1c848c487bd43032808e59dd8328d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "757cfbfe0d17ee6f22fe97e536d463047d451b47cf9d11e2b7d1398b0ef274dd"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ cargo-fuzz = true
|
|||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
bincodev1 = {package = "bincode", version = "1.3.3"}
|
||||
serde = { version = "1.0.135", features = ["derive"] }
|
||||
|
||||
[dependencies.bincode]
|
||||
path = ".."
|
||||
|
|
@ -23,3 +25,9 @@ name = "roundtrip"
|
|||
path = "fuzz_targets/roundtrip.rs"
|
||||
test = false
|
||||
doc = false
|
||||
|
||||
[[bin]]
|
||||
name = "compat"
|
||||
path = "fuzz_targets/compat.rs"
|
||||
test = false
|
||||
doc = false
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use std::ffi::CString;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||
use std::num::{NonZeroI128, NonZeroI32, NonZeroU128, NonZeroU32};
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
#[derive(bincode::Decode, bincode::Encode, PartialEq, Debug, serde::Serialize, serde::Deserialize, Eq, PartialOrd, Ord)]
|
||||
enum AllTypes {
|
||||
BTreeMap(BTreeMap<u8, AllTypes>),
|
||||
BTreeSet(BTreeSet<AllTypes>),
|
||||
VecDeque(VecDeque<AllTypes>),
|
||||
Vec(Vec<u8>),
|
||||
String(String),
|
||||
Box(Box<u8>),
|
||||
BoxSlice(Box<[u8]>),
|
||||
CString(CString),
|
||||
SystemTime(SystemTime),
|
||||
Duration(Duration),
|
||||
PathBuf(PathBuf),
|
||||
IpAddr(IpAddr),
|
||||
Ipv4Addr(Ipv4Addr),
|
||||
Ipv6Addr(Ipv6Addr),
|
||||
SocketAddr(SocketAddr),
|
||||
SocketAddrV4(SocketAddrV4),
|
||||
SocketAddrV6(SocketAddrV6),
|
||||
NonZeroU32(NonZeroU32),
|
||||
NonZeroI32(NonZeroI32),
|
||||
NonZeroU128(NonZeroU128),
|
||||
NonZeroI128(NonZeroI128),
|
||||
I128(i128),
|
||||
I8(i8),
|
||||
U128(u128),
|
||||
U8(u8),
|
||||
// Cow(Cow<'static, [u8]>), Blocked, see comment on decode
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let config = bincode::config::legacy().with_limit::<1024>();
|
||||
#[allow(deprecated)]
|
||||
let mut configv1 = bincodev1::config();
|
||||
configv1.limit(1024);
|
||||
let bincode_v1: Result<AllTypes, _> = configv1.deserialize(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");
|
||||
}
|
||||
});
|
||||
|
|
@ -15,13 +15,13 @@ enum AllTypes {
|
|||
BTreeMap(BTreeMap<u8, u8>),
|
||||
HashMap(HashMap<u8, u8>),
|
||||
BTreeSet(BTreeSet<u8>),
|
||||
VecDeque(VecDeque<u8>),
|
||||
Vec(Vec<u8>),
|
||||
VecDeque(VecDeque<AllTypes>),
|
||||
Vec(Vec<AllTypes>),
|
||||
String(String),
|
||||
Box(Box<u8>),
|
||||
BoxSlice(Box<[u8]>),
|
||||
Rc(Rc<u8>),
|
||||
Arc(Arc<u8>),
|
||||
Box(Box<AllTypes>),
|
||||
BoxSlice(Box<[AllTypes]>),
|
||||
Rc(Rc<AllTypes>),
|
||||
Arc(Arc<AllTypes>),
|
||||
CString(CString),
|
||||
SystemTime(SystemTime),
|
||||
Duration(Duration),
|
||||
|
|
|
|||
Loading…
Reference in New Issue