Skip to content

Commit 0c4976a

Browse files
Add gix-commitgraph::File fuzzer
1 parent c1e4c62 commit 0c4976a

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

gix-commitgraph/fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

gix-commitgraph/fuzz/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "gix-commitgraph-fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
anyhow = "1.0.76"
12+
arbitrary = { version = "1.3.2", features = ["derive"] }
13+
libfuzzer-sys = "0.4"
14+
tempfile = "3.8.1"
15+
16+
[dependencies.gix-commitgraph]
17+
path = ".."
18+
19+
# Prevent this from interfering with workspaces
20+
[workspace]
21+
members = ["."]
22+
23+
[profile.release]
24+
debug = 1
25+
26+
[[bin]]
27+
name = "fuzz_file"
28+
path = "fuzz_targets/fuzz_file.rs"
29+
test = false
30+
doc = false
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![no_main]
2+
3+
use anyhow::Result;
4+
use arbitrary::Arbitrary;
5+
use gix_commitgraph::File;
6+
use libfuzzer_sys::fuzz_target;
7+
use std::fs;
8+
use std::hint::black_box;
9+
use tempfile::NamedTempFile;
10+
11+
fn fuzz(data: &[u8]) -> Result<()> {
12+
let named_temp_file = NamedTempFile::new()?;
13+
fs::write(named_temp_file.path(), data).expect("Unable to write fuzzed file");
14+
let file = File::try_from(named_temp_file.path())?;
15+
16+
_ = black_box(file.iter_base_graph_ids().count());
17+
_ = black_box(file.iter_commits().count());
18+
_ = black_box(file.iter_ids().count());
19+
20+
let _ = black_box(file.checksum());
21+
let _ = black_box(file.verify_checksum());
22+
let _ = black_box(file.object_hash());
23+
24+
Ok(())
25+
}
26+
27+
fuzz_target!(|data: &[u8]| {
28+
_ = black_box(fuzz(data));
29+
});

0 commit comments

Comments
 (0)