xref: /webrtc/sctp/src/fuzz_artifact_test.rs (revision 62d3ee5b)
1 //! # What are these tests?
2 //!
3 //! These tests ensure that regressions in the unmarshaling code are caught.
4 //!
5 //! They check all artifacts of the fuzzer that crashed this lib, and make sure they no longer crash the library.
6 //!
7 //! The content of the files is mostly garbage, but it triggers "intersting" behaviour in the unmarshaling code.
8 //! So if your change fails one of these tests you probably made an error somwhere.
9 //!
10 //! Sadly these tests cannot really tell you where your error is specifically outside the standard backtrace rust will provide to you. Sorry.
11 
12 use bytes::Bytes;
13 
14 #[test]
param_crash_artifacts()15 fn param_crash_artifacts() {
16     for artifact in std::fs::read_dir("fuzz/artifacts/param").unwrap() {
17         let artifact = artifact.unwrap();
18         if artifact
19             .file_name()
20             .into_string()
21             .unwrap()
22             .starts_with("crash-")
23         {
24             let artifact = std::fs::read(artifact.path()).unwrap();
25             crate::param::build_param(&Bytes::from(artifact)).ok();
26         }
27     }
28 }
29 
30 #[test]
packet_crash_artifacts()31 fn packet_crash_artifacts() {
32     for artifact in std::fs::read_dir("fuzz/artifacts/packet").unwrap() {
33         let artifact = artifact.unwrap();
34         if artifact
35             .file_name()
36             .into_string()
37             .unwrap()
38             .starts_with("crash-")
39         {
40             let artifact = std::fs::read(artifact.path()).unwrap();
41             crate::packet::Packet::unmarshal(&Bytes::from(artifact)).ok();
42         }
43     }
44 }
45