Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gix-merge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ gix-odb = { path = "../gix-odb" }
gix-utils = { path = "../gix-utils" }
termtree = "1.0.0"
pretty_assertions = "1.4.0"
arbitrary = { version = "1.4.2", features = ["derive"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
Binary file not shown.
72 changes: 72 additions & 0 deletions gix-merge/tests/merge/blob/builtin_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ fn binary() {
}

mod text {
use arbitrary::Arbitrary;
use bstr::ByteSlice;
use gix_merge::blob::{
builtin_driver,
builtin_driver::text::{Conflict, ConflictStyle},
Resolution,
};
use pretty_assertions::assert_str_eq;
use std::num::NonZero;

const DIVERGING: &[&str] = &[
// Somehow, on in zdiff mode, it's different, and I wasn't able to figure out the rule properly.
Expand Down Expand Up @@ -140,6 +142,76 @@ mod text {
}
}

/// This test reproduces what the fuzzer does, allowing it to accept `Arbitrary` input produced by the fuzzer.
#[test]
fn clusterfuzz_timeout_regression() {
#[derive(Debug, Arbitrary)]
struct FuzzCtx<'a> {
base: &'a [u8],
ours: &'a [u8],
theirs: &'a [u8],
marker_size: NonZero<u8>,
}
fn run_fuzz_case(ours: &[u8], base: &[u8], theirs: &[u8], marker_size: NonZero<u8>) {
let mut out = Vec::new();
let mut input = imara_diff::intern::InternedInput::default();
for diff_algorithm in [
imara_diff::Algorithm::Histogram,
imara_diff::Algorithm::Myers,
imara_diff::Algorithm::MyersMinimal,
] {
let mut options = builtin_driver::text::Options {
diff_algorithm,
conflict: Default::default(),
};
for (left, right) in [(ours, theirs), (theirs, ours)] {
let resolution = gix_merge::blob::builtin_driver::text(
&mut out,
&mut input,
Default::default(),
left,
base,
right,
options,
);
if resolution == Resolution::Conflict {
for conflict in [
Conflict::ResolveWithOurs,
Conflict::ResolveWithTheirs,
Conflict::ResolveWithUnion,
Conflict::Keep {
style: ConflictStyle::Diff3,
marker_size,
},
Conflict::Keep {
style: ConflictStyle::ZealousDiff3,
marker_size,
},
] {
options.conflict = conflict;
gix_merge::blob::builtin_driver::text(
&mut out,
&mut input,
Default::default(),
left,
base,
right,
options,
);
}
}
}
}
}

let ctx = FuzzCtx::arbitrary(&mut arbitrary::Unstructured::new(include_bytes!(
"../../fixtures/clusterfuzz-testcase-minimized-gix-merge-blob-6377298803884032"
)))
.expect("testcase matches the historical fuzz target input layout");

run_fuzz_case(ctx.ours, ctx.base, ctx.theirs, ctx.marker_size);
}

#[test]
fn run_baseline() -> crate::Result {
let root = gix_testtools::scripted_fixture_read_only("text-baseline.sh")?;
Expand Down
Loading