Skip to content

Commit

Permalink
Fuzz more of gix-ref log
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-brough committed Dec 23, 2023
1 parent 8e2db97 commit 04875ec
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions gix-ref/fuzz/fuzz_targets/fuzz_log.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
#![no_main]

use anyhow::Result;
use arbitrary::Arbitrary;
use gix_ref::file::log;
use libfuzzer_sys::fuzz_target;
use std::hint::black_box;

fn fuzz(line: &[u8]) -> Result<()> {
let line = log::LineRef::from_bytes(line)?;
#[derive(Arbitrary, Debug)]
struct Ctx<'a> {
line_ref: &'a [u8],
multi_line_reverse: &'a [u8],
multi_line_forward: &'a [u8],
}

fn fuzz(ctx: Ctx) -> Result<()> {
let line = log::LineRef::from_bytes(ctx.line_ref)?;
_ = black_box(line.previous_oid());
_ = black_box(line.new_oid());

let mut buf = [0u8; 1024];
let read = std::io::Cursor::new(ctx.multi_line_reverse);
let mut iter = gix_ref::file::log::iter::reverse(read, &mut buf)?;
_ = black_box(iter.map(|x| black_box(x)).count());

let mut iter = gix_ref::file::log::iter::forward(ctx.multi_line_forward);
_ = black_box(iter.map(|x| black_box(x)).count());

Ok(())
}

fuzz_target!(|ctx: &[u8]| {
fuzz_target!(|ctx: Ctx| {
_ = black_box(fuzz(ctx));
});

0 comments on commit 04875ec

Please sign in to comment.