diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 76eb2aa9..35a387e3 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -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]] @@ -53,8 +64,63 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +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.4" +version = "0.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e85ed1066abcc0ea331cce3ce83cccf30ae9900529ca46f353b22ca79b56b8" +checksum = "757cfbfe0d17ee6f22fe97e536d463047d451b47cf9d11e2b7d1398b0ef274dd" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index ddf1d280..44ecfac7 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -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 diff --git a/fuzz/fuzz_targets/compat.rs b/fuzz/fuzz_targets/compat.rs new file mode 100644 index 00000000..568089f9 --- /dev/null +++ b/fuzz/fuzz_targets/compat.rs @@ -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), + BTreeSet(BTreeSet), + VecDeque(VecDeque), + Vec(Vec), + String(String), + Box(Box), + 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 = 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"); + } +}); diff --git a/fuzz/fuzz_targets/roundtrip.rs b/fuzz/fuzz_targets/roundtrip.rs index 198f32a9..e2a15e81 100644 --- a/fuzz/fuzz_targets/roundtrip.rs +++ b/fuzz/fuzz_targets/roundtrip.rs @@ -15,13 +15,13 @@ enum AllTypes { BTreeMap(BTreeMap), HashMap(HashMap), BTreeSet(BTreeSet), - VecDeque(VecDeque), - Vec(Vec), + VecDeque(VecDeque), + Vec(Vec), String(String), - Box(Box), - BoxSlice(Box<[u8]>), - Rc(Rc), - Arc(Arc), + Box(Box), + BoxSlice(Box<[AllTypes]>), + Rc(Rc), + Arc(Arc), CString(CString), SystemTime(SystemTime), Duration(Duration),