Visitar URL original
Add a fuzzer and a benchmark for tree-to-tree diffs by yerseg · Pull Request #7395 · libgit2/libgit2 · GitHub
Skip to content

Add a fuzzer and a benchmark for tree-to-tree diffs - #7395

Open
yerseg wants to merge 2 commits into
libgit2:mainfrom
yerseg:diff-tree-fuzzer-and-benchmark
Open

yerseg wants to merge 2 commits into
libgit2:mainfrom
yerseg:diff-tree-fuzzer-and-benchmark

Conversation

@yerseg

@yerseg yerseg commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

This adds a fuzzer and a benchmark for git_diff_tree_to_tree. I wrote them while working on #6863.

The fuzzer (fuzzers/diff_tree_fuzzer.c) builds two trees from the input. The second tree is derived from the first one, so they share subtrees. It diffs them with flags, pathspecs and a notify callback taken from the input, and checks the result against the same diff with GIT_DIFF_INCLUDE_UNMODIFIED, ignoring the unmodified deltas. That option forces every subtree to be read, so this checks that skipping unmodified trees (#6863) doesn't change anything. Objects are kept in a mempack backend that's reset after each input.

It found bugs pretty quickly. On main it hits #7392 in 2 out of 3 two-minute runs. On the first version of #6863 it found a difference in each of 6 runs of 90 seconds.

The corpus has those 6 inputs plus a minimized set from a longer run. I left out the input for #7392, so the standalone run passes on main until that's fixed.

The benchmark (benchmarks/libgit2/diff.c) diffs a tree with 32768 files (32 × 32 directories with 32 files each) against itself and against a copy with one changed file. RelWithDebInfo:

main with #6863
tree vs. itself 4.05 ms 16.1 µs
one file changed 4.05 ms 24.6 µs

Build two trees from the input, the second one from the first one with
some changes, and diff them with flags, pathspecs and a notify callback
from the input.  Compare the deltas with the deltas of the same diff
with GIT_DIFF_INCLUDE_UNMODIFIED, which reads every subtree, without
the unmodified deltas.
Diff a tree of 32768 files with itself and with a tree where one file
changed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant