From a285eee74559e329ebe2ef61f057dd713266fdc6 Mon Sep 17 00:00:00 2001 From: David Holroyd Date: Wed, 22 Jul 2020 14:26:41 +0100 Subject: [PATCH] Add fuzzing framework. Fixes #7 --- fuzz/.gitignore | 4 +++ fuzz/Cargo.toml | 27 ++++++++++++++++++ fuzz/fuzz_targets/fuzz_target_1.rs | 46 ++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/fuzz_target_1.rs diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..572e03b --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ + +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..8192391 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,27 @@ + +[package] +name = "scte35-reader-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.3" +mpeg2ts-reader = "0.13" + +[dependencies.scte35-reader] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "fuzz_target_1" +path = "fuzz_targets/fuzz_target_1.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/fuzz_target_1.rs b/fuzz/fuzz_targets/fuzz_target_1.rs new file mode 100644 index 0000000..be1e4bc --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_target_1.rs @@ -0,0 +1,46 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use scte35_reader::*; +use mpeg2ts_reader::demultiplex; +use mpeg2ts_reader::psi; +use mpeg2ts_reader::psi::WholeCompactSyntaxPayloadParser; + +mpeg2ts_reader::demux_context!( + FuzzDemuxContext, + demultiplex::NullPacketFilter + ); +impl FuzzDemuxContext { + fn do_construct( + &mut self, + _req: demultiplex::FilterRequest<'_, '_>, + ) -> demultiplex::NullPacketFilter { + unimplemented!(); + } +} + +struct FuzzSpliceInfoProcessor; +impl SpliceInfoProcessor for FuzzSpliceInfoProcessor { + fn process( + &self, + header: SpliceInfoHeader<'_>, + command: SpliceCommand, + descriptors: SpliceDescriptors<'_>, + ) { + // The debug implementations should call every accessor method under the hood, + format!("{:?}", header); + format!("{:?}", command); + + for d in &descriptors { + format!("{:?}", d); + } + } +} +fuzz_target!(|data: &[u8]| { + if data.len() < psi::SectionCommonHeader::SIZE { + return; + } + let mut parser = Scte35SectionProcessor::new(FuzzSpliceInfoProcessor); + let header = psi::SectionCommonHeader::new(&data[..psi::SectionCommonHeader::SIZE]); + let mut ctx = FuzzDemuxContext::new(); + parser.section(&mut ctx, &header, &data[..]); +});