Skip to content

Commit 0552b83

Browse files
authored
Merge pull request #1906 from DaveLak/fuzzing-fix-missing-git-in-clusterfuzz
Fix Fuzzer Crash in ClusterFuzz Due to Missing Git Executable
2 parents bc7bd22 + f4b95cf commit 0552b83

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

fuzzing/fuzz-targets/fuzz_config.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
import atheris
2121
import sys
2222
import io
23+
import os
2324
from configparser import MissingSectionHeaderError, ParsingError
2425

2526
with atheris.instrument_imports():
26-
from git import GitConfigParser
27+
import git
2728

2829

2930
def TestOneInput(data):
31+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
32+
path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
33+
git.refresh(path_to_bundled_git_binary)
34+
3035
sio = io.BytesIO(data)
3136
sio.name = "/tmp/fuzzconfig.config"
32-
git_config = GitConfigParser(sio)
37+
git_config = git.GitConfigParser(sio)
3338
try:
3439
git_config.read()
3540
except (MissingSectionHeaderError, ParsingError, UnicodeDecodeError):

fuzzing/fuzz-targets/fuzz_tree.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
import shutil
2525

2626
with atheris.instrument_imports():
27-
from git.objects import Tree
28-
from git.repo import Repo
27+
import git
2928

3029

3130
def TestOneInput(data):
31+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
32+
path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
33+
git.refresh(path_to_bundled_git_binary)
34+
3235
fdp = atheris.FuzzedDataProvider(data)
3336
git_dir = "/tmp/.git"
3437
head_file = os.path.join(git_dir, "HEAD")
@@ -46,9 +49,9 @@ def TestOneInput(data):
4649
os.mkdir(common_dir)
4750
os.mkdir(objects_dir)
4851

49-
_repo = Repo("/tmp/")
52+
_repo = git.Repo("/tmp/")
5053

51-
fuzz_tree = Tree(_repo, Tree.NULL_BIN_SHA, 0, "")
54+
fuzz_tree = git.Tree(_repo, git.Tree.NULL_BIN_SHA, 0, "")
5255
try:
5356
fuzz_tree._deserialize(io.BytesIO(data))
5457
except IndexError:

fuzzing/oss-fuzz-scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ find "$SEED_DATA_DIR" \( -name '*_seed_corpus.zip' -o -name '*.options' -o -name
1414

1515
# Build fuzzers in $OUT.
1616
find "$SRC/gitpython/fuzzing" -name 'fuzz_*.py' -print0 | while IFS= read -r -d '' fuzz_harness; do
17-
compile_python_fuzzer "$fuzz_harness"
17+
compile_python_fuzzer "$fuzz_harness" --add-binary="$(command -v git):."
1818

1919
common_base_dictionary_filename="$SEED_DATA_DIR/__base.dict"
2020
if [[ -r "$common_base_dictionary_filename" ]]; then

0 commit comments

Comments
 (0)