Fix Fuzzer Crash in ClusterFuzz Due to Missing Git Executable · gitpython-developers/GitPython@f4b95cf · GitHub
Skip to content

Commit f4b95cf

Browse files
committed
Fix Fuzzer Crash in ClusterFuzz Due to Missing Git Executable
A Git executable is not globally available in the ClusterFuzz container environment where OSS-Fuzz executes fuzz tests, causing an error in the fuzz harnesses when GitPython attempts to initialize, crashing the tests before they can run. To avoid this issue, we bundle the `git` binary that is available in the OSS-Fuzz build container with the fuzz harness via Pyinstaller's `--add-binary` flag in `build.sh` and use GitPython's `git.refresh(<full-path-to-git-executable>)` method inside a Pyinstaller runtime check to initialize GitPython with the bundled Git executable when running from the bundled application. In all other execution environments, we assume a `git` executable is available globally. Fixes: - #1905 - google/oss-fuzz#10600
1 parent bc7bd22 commit f4b95cf

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

fuzzing/fuzz-targets/fuzz_config.py

Lines changed: 7 additions & 2 deletions

fuzzing/fuzz-targets/fuzz_tree.py

Lines changed: 7 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)