Skip to content

Commit

Permalink
Fuzz more of pathspec patterns
Browse files Browse the repository at this point in the history
- Fuzz more of the API
- Add associated dictionary
  • Loading branch information
nathaniel-brough committed Dec 30, 2023
1 parent 34e4a16 commit 6ac89e5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions gix-pathspec/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
cargo-fuzz = true

[dependencies]
anyhow = "1.0.77"
libfuzzer-sys = "0.4"

[dependencies.gix-pathspec]
Expand Down
22 changes: 22 additions & 0 deletions gix-pathspec/fuzz/fuzz_targets/parse.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ---- Magic signatures ----
":(top)"
"top"
":/"

":(icase)"
"icase"

":(literal)"
"literal"

":(glob)"
"glob"

# We can't close attr as they take arguments.
":(attr:"
":(attr:!"
"attr"

":(exclude)"
"exclude"
":!"
15 changes: 14 additions & 1 deletion gix-pathspec/fuzz/fuzz_targets/parse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#![no_main]
use anyhow::Result;
use libfuzzer_sys::fuzz_target;
use std::hint::black_box;

fn fuzz(data: &[u8]) -> Result<()> {
let pattern = gix_pathspec::parse(data, Default::default())?;
_ = black_box(pattern.is_nil());
_ = black_box(pattern.prefix_directory());
_ = black_box(pattern.path());
// TODO: Fuzz normalize
_ = black_box(pattern.is_excluded());
_ = black_box(pattern.to_bstring());
Ok(())
}

fuzz_target!(|data: &[u8]| {
let _a = gix_pathspec::parse(data, Default::default());
_ = black_box(fuzz(data));
});

0 comments on commit 6ac89e5

Please sign in to comment.