Skip to content

Commit

Permalink
Use fuzzed data for all git.Blob arguments
Browse files Browse the repository at this point in the history
This increases the edges reached by the fuzzer, making for a more
effective test with higher coverage.
  • Loading branch information
DaveLak committed May 4, 2024
1 parent 48abb1c commit 6823e45
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions fuzzing/fuzz-targets/fuzz_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ def TestOneInput(data):

with tempfile.TemporaryDirectory() as temp_dir:
repo = git.Repo.init(path=temp_dir)
blob = git.Blob(
repo,
**{
"binsha": git.Blob.NULL_BIN_SHA,
"path": fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes()),
},
)
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

Expand Down

0 comments on commit 6823e45

Please sign in to comment.