Skip to content

Commit

Permalink
Add a fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
dholroyd committed Feb 23, 2024
1 parent 5d5b898 commit f1f7190
Show file tree
Hide file tree
Showing 39 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

target
artifacts
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "adts-reader-fuzz"
version = "0.0.1"
authors = ["Automatically generated"]
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
adts-reader = { path = ".." }
libfuzzer-sys = "0.3"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
19 changes: 19 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Fuzz testing `adts-reader`

## Setup

If you don't already have [cargo-fuzz](https://rust-fuzz.github.io/book/introduction.html) installed.

```
cargo +nightly install cargo-fuzz
```

## Testing

To perform fuzz testing,

```
cargo +nightly fuzz run fuzz_target_1
```

(The fuzz test will keep running until it either finds a fault, or you kill the process.)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate adts_reader;

use adts_reader::*;

struct NullConsumer {}

impl AdtsConsumer for NullConsumer {
fn new_config(
&mut self,
mpeg_version: MpegVersion,
protection: ProtectionIndicator,
aot: AudioObjectType,
freq: SamplingFrequency,
private_bit: u8,
channels: ChannelConfiguration,
originality: Originality,
home: u8,
) {
}
fn payload(&mut self, buffer_fullness: u16, number_of_blocks: u8, buf: &[u8]) {}
fn error(&mut self, err: AdtsParseError) {}
}

fuzz_target!(|data: &[u8]| {
let mut p = AdtsParser::new(NullConsumer {});
p.push(data);
});

0 comments on commit f1f7190

Please sign in to comment.