-
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1e4c62
commit 0c4976a
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "gix-commitgraph-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
anyhow = "1.0.76" | ||
arbitrary = { version = "1.3.2", features = ["derive"] } | ||
libfuzzer-sys = "0.4" | ||
tempfile = "3.8.1" | ||
|
||
[dependencies.gix-commitgraph] | ||
path = ".." | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "fuzz_file" | ||
path = "fuzz_targets/fuzz_file.rs" | ||
test = false | ||
doc = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![no_main] | ||
|
||
use anyhow::Result; | ||
use arbitrary::Arbitrary; | ||
use gix_commitgraph::File; | ||
use libfuzzer_sys::fuzz_target; | ||
use std::fs; | ||
use std::hint::black_box; | ||
use tempfile::NamedTempFile; | ||
|
||
fn fuzz(data: &[u8]) -> Result<()> { | ||
let named_temp_file = NamedTempFile::new()?; | ||
fs::write(named_temp_file.path(), data).expect("Unable to write fuzzed file"); | ||
let file = File::try_from(named_temp_file.path())?; | ||
|
||
_ = black_box(file.iter_base_graph_ids().count()); | ||
_ = black_box(file.iter_commits().count()); | ||
_ = black_box(file.iter_ids().count()); | ||
|
||
let _ = black_box(file.checksum()); | ||
let _ = black_box(file.verify_checksum()); | ||
let _ = black_box(file.object_hash()); | ||
|
||
Ok(()) | ||
} | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
_ = black_box(fuzz(data)); | ||
}); |