Skip to content

Commit d83b4e0

Browse files
Fuzz more of gix-ref log
1 parent 27490d9 commit d83b4e0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gix-ref/fuzz/fuzz_targets/fuzz_log.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
#![no_main]
22

33
use anyhow::Result;
4+
use arbitrary::Arbitrary;
45
use gix_ref::file::log;
56
use libfuzzer_sys::fuzz_target;
67
use std::hint::black_box;
78

8-
fn fuzz(line: &[u8]) -> Result<()> {
9-
let line = log::LineRef::from_bytes(line)?;
9+
#[derive(Arbitrary, Debug)]
10+
struct Ctx<'a> {
11+
line_ref: &'a [u8],
12+
multi_line_reverse: &'a [u8],
13+
multi_line_forward: &'a [u8],
14+
}
15+
16+
fn fuzz(ctx: Ctx) -> Result<()> {
17+
let line = log::LineRef::from_bytes(ctx.line_ref)?;
1018
_ = black_box(line.previous_oid());
1119
_ = black_box(line.new_oid());
20+
21+
let mut buf = [0u8; 1024];
22+
let read = std::io::Cursor::new(ctx.multi_line_reverse);
23+
let mut iter = gix_ref::file::log::iter::reverse(read, &mut buf)?;
24+
_ = black_box(iter.map(|x| black_box(x)).count());
25+
26+
let mut iter = gix_ref::file::log::iter::forward(ctx.multi_line_forward);
27+
_ = black_box(iter.map(|x| black_box(x)).count());
28+
1229
Ok(())
1330
}
1431

15-
fuzz_target!(|ctx: &[u8]| {
32+
fuzz_target!(|ctx: Ctx| {
1633
_ = black_box(fuzz(ctx));
1734
});

0 commit comments

Comments
 (0)