Skip to content

Commit

Permalink
Add fuzz test
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 committed Aug 28, 2024
1 parent ed8b0de commit fca0dab
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ jobs:
strategy:
matrix:
item:
- { name: pica-record-ref, fuzz-dir: crates/pica-record/fuzz, target: fuzz-record-ref, max-total-time: 300 }
- { name: pica-format, fuzz-dir: crates/pica-format/fuzz, target: fuzz-format, max-total-time: 300 }
- { name: pica-path, fuzz-dir: crates/pica-path/fuzz, target: fuzz-path, max-total-time: 300 }
- { name: pica-record-matcher, fuzz-dir: crates/pica-matcher/fuzz, target: fuzz-record-matcher, max-total-time: 300 }
- { name: pica-record-ref, fuzz-dir: crates/pica-record/fuzz, target: fuzz-record-ref, max-total-time: 300 }
- { name: pica-select-query, fuzz-dir: crates/pica-select/fuzz, target: fuzz-query, max-total-time: 300 }
- { name: pica-path, fuzz-dir: crates/pica-path/fuzz, target: fuzz-path, max-total-time: 300 }
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
Expand Down
4 changes: 4 additions & 0 deletions crates/pica-format/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
24 changes: 24 additions & 0 deletions crates/pica-format/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "pica-format-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.pica-format]
path = ".."

[workspace]
members = ["."]

[[bin]]
name = "fuzz-format"
path = "fuzz_targets/fuzz_format.rs"
test = false
doc = false
bench = false
12 changes: 12 additions & 0 deletions crates/pica-format/fuzz/fuzz_targets/fuzz_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_main]

use std::str::FromStr;

use libfuzzer_sys::fuzz_target;
use pica_format::Format;

fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
let _format = Format::from_str(s);
}
});

0 comments on commit fca0dab

Please sign in to comment.