Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git.Blob Fuzz Target #1911

Merged
merged 2 commits into from
May 5, 2024
Merged
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
1 change: 1 addition & 0 deletions fuzzing/dictionaries/fuzz_blob.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\\377\\377\\377\\377\\377\\377\\377\\377"
40 changes: 40 additions & 0 deletions fuzzing/fuzz-targets/fuzz_blob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import atheris
import sys
import os
import tempfile

if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary

with atheris.instrument_imports():
import git


def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)

with tempfile.TemporaryDirectory() as temp_dir:
repo = git.Repo.init(path=temp_dir)
binsha = fdp.ConsumeBytes(20)
mode = fdp.ConsumeInt(fdp.ConsumeIntInRange(0, fdp.remaining_bytes()))
path = fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes())

try:
blob = git.Blob(repo, binsha, mode, path)
except AssertionError as e:
if "Require 20 byte binary sha, got" in str(e):
return -1
else:
raise e

_ = blob.mime_type


def main():
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()


if __name__ == "__main__":
main()
Loading