/src/bincode/fuzz/fuzz_targets/roundtrip.rs
Line | Count | Source |
1 | | #![no_main] |
2 | | use libfuzzer_sys::fuzz_target; |
3 | | |
4 | | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, 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::rc::Rc; |
10 | | use std::sync::Arc; |
11 | | use std::time::{Duration, SystemTime}; |
12 | | |
13 | 338 | #[derive(bincode::Decode, bincode::Encode, PartialEq, Debug)] Unexecuted instantiation: <roundtrip::AllTypes as bincode::de::BorrowDecode<_>>::borrow_decode::<_> <roundtrip::AllTypes as bincode::de::Decode<()>>::decode::<bincode::de::decoder::DecoderImpl<bincode::de::read::SliceReader, bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::Limit<1024>>, ()>> Line | Count | Source | 13 | 338 | #[derive(bincode::Decode, bincode::Encode, PartialEq, Debug)] |
Unexecuted instantiation: <roundtrip::AllTypes as bincode::enc::Encode>::encode::<bincode::enc::encoder::EncoderImpl<bincode::enc::write::SizeWriter, bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::Limit<1024>>>> Unexecuted instantiation: <roundtrip::AllTypes as bincode::enc::Encode>::encode::<bincode::enc::encoder::EncoderImpl<bincode::features::impl_alloc::VecWriter, bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::Limit<1024>>>> |
14 | | enum AllTypes { |
15 | | BTreeMap(BTreeMap<u8, u8>), |
16 | | HashMap(HashMap<u8, u8>), |
17 | | HashSet(HashSet<u8>), |
18 | | BTreeSet(BTreeSet<u8>), |
19 | | VecDeque(VecDeque<AllTypes>), |
20 | | Vec(Vec<AllTypes>), |
21 | | String(String), |
22 | | Box(Box<AllTypes>), |
23 | | BoxSlice(Box<[AllTypes]>), |
24 | | Rc(Rc<AllTypes>), |
25 | | Arc(Arc<AllTypes>), |
26 | | CString(CString), |
27 | | SystemTime(SystemTime), |
28 | | Duration(Duration), |
29 | | PathBuf(PathBuf), |
30 | | IpAddr(IpAddr), |
31 | | Ipv4Addr(Ipv4Addr), |
32 | | Ipv6Addr(Ipv6Addr), |
33 | | SocketAddr(SocketAddr), |
34 | | SocketAddrV4(SocketAddrV4), |
35 | | SocketAddrV6(SocketAddrV6), |
36 | | NonZeroU32(NonZeroU32), |
37 | | NonZeroI32(NonZeroI32), |
38 | | NonZeroU128(NonZeroU128), |
39 | | NonZeroI128(NonZeroI128), |
40 | | // Cow(Cow<'static, [u8]>), Blocked, see comment on decode |
41 | | } |
42 | | |
43 | | fuzz_target!(|data: &[u8]| { |
44 | | let config = bincode::config::standard().with_limit::<1024>(); |
45 | | let result: Result<(AllTypes, _), _> = bincode::decode_from_slice(data, config); |
46 | | |
47 | | if let Ok((before, _)) = result { |
48 | | let encoded = bincode::encode_to_vec(&before, config).expect("round trip"); |
49 | | let (after, _) = bincode::decode_from_slice(&encoded, config).unwrap(); |
50 | | assert_eq!(before, after); |
51 | | } |
52 | | }); |