/src/bincode/fuzz/fuzz_targets/compat.rs
Line | Count | Source |
1 | | #![no_main] |
2 | | use libfuzzer_sys::fuzz_target; |
3 | | |
4 | | use std::collections::{BTreeMap, BTreeSet, VecDeque}; |
5 | | use std::ffi::CString; |
6 | | use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; |
7 | | use std::num::{NonZeroI128, NonZeroI32, NonZeroU128, NonZeroU32}; |
8 | | use std::path::PathBuf; |
9 | | use std::time::{Duration, SystemTime}; |
10 | | |
11 | | #[derive( |
12 | 828 | bincode::Decode, Unexecuted instantiation: <compat::AllTypes as bincode::de::BorrowDecode<_>>::borrow_decode::<_> <compat::AllTypes as bincode::de::Decode<()>>::decode::<bincode::de::decoder::DecoderImpl<bincode::de::read::SliceReader, bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Fixint, bincode::config::Limit<1024>>, ()>> Line | Count | Source | 12 | 828 | bincode::Decode, |
|
13 | 0 | bincode::Encode, |
14 | | PartialEq, |
15 | | Debug, |
16 | | serde::Serialize, |
17 | 41.8k | serde::Deserialize, Unexecuted instantiation: <<compat::AllTypes as serde::de::Deserialize>::deserialize::__FieldVisitor as serde::de::Visitor>::expecting Unexecuted instantiation: <<compat::AllTypes as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::expecting <<compat::AllTypes as serde::de::Deserialize>::deserialize::__Field as serde::de::Deserialize>::deserialize::<serde::de::value::U32Deserializer<alloc::boxed::Box<bincode::error::ErrorKind>>> Line | Count | Source | 17 | 41.8k | serde::Deserialize, |
|
18 | | Eq, |
19 | | PartialOrd, |
20 | | Ord, |
21 | | )] |
22 | | enum AllTypes { |
23 | | BTreeMap(BTreeMap<u8, AllTypes>), |
24 | | BTreeSet(BTreeSet<AllTypes>), |
25 | | VecDeque(VecDeque<AllTypes>), |
26 | | Vec(Vec<u8>), |
27 | | String(String), |
28 | | Box(Box<u8>), |
29 | | BoxSlice(Box<[u8]>), |
30 | | CString(CString), |
31 | | SystemTime(SystemTime), |
32 | | Duration(Duration), |
33 | | PathBuf(PathBuf), |
34 | | IpAddr(IpAddr), |
35 | | Ipv4Addr(Ipv4Addr), |
36 | | Ipv6Addr(Ipv6Addr), |
37 | | SocketAddr(SocketAddr), |
38 | | SocketAddrV4(SocketAddrV4), |
39 | | SocketAddrV6(SocketAddrV6), |
40 | | NonZeroU32(NonZeroU32), |
41 | | NonZeroI32(NonZeroI32), |
42 | | NonZeroU128(NonZeroU128), |
43 | | NonZeroI128(NonZeroI128), |
44 | | I128(i128), |
45 | | I8(i8), |
46 | | U128(u128), |
47 | | U8(u8), |
48 | | // Cow(Cow<'static, [u8]>), Blocked, see comment on decode |
49 | | } |
50 | | |
51 | | fuzz_target!(|data: &[u8]| { |
52 | | let config = bincode::config::legacy().with_limit::<1024>(); |
53 | | #[allow(deprecated)] |
54 | | let mut configv1 = bincodev1::config(); |
55 | | configv1.limit(1024); |
56 | | let bincode_v1: Result<AllTypes, _> = configv1.deserialize_from(data); |
57 | | let bincode_v2: Result<(AllTypes, _), _> = bincode::decode_from_slice(data, config); |
58 | | |
59 | | match (&bincode_v1, &bincode_v2) { |
60 | | (Err(e), _) if e.to_string() == "the size limit has been reached" => {} |
61 | | (_, Err(bincode::error::DecodeError::LimitExceeded)) => {} |
62 | | (Ok(bincode_v1), Ok((bincode_v2, _))) if bincode_v1 != bincode_v2 => { |
63 | | println!("Bytes: {:?}", data); |
64 | | println!("Bincode V1: {:?}", bincode_v1); |
65 | | println!("Bincode V2: {:?}", bincode_v2); |
66 | | panic!("failed equality check"); |
67 | | } |
68 | | (Ok(_), Err(_)) | (Err(_), Ok(_)) => { |
69 | | println!("Bytes: {:?}", data); |
70 | | println!("Bincode V1: {:?}", bincode_v1); |
71 | | println!("Bincode V2: {:?}", bincode_v2); |
72 | | panic!("failed equality check"); |
73 | | } |
74 | | |
75 | | _ => {} |
76 | | } |
77 | | }); |