Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6823e45

Browse files
committed
Use fuzzed data for all git.Blob arguments
This increases the edges reached by the fuzzer, making for a more effective test with higher coverage.
1 parent 48abb1c commit 6823e45

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

fuzzing/fuzz-targets/fuzz_blob.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ def TestOneInput(data):
1616

1717
with tempfile.TemporaryDirectory() as temp_dir:
1818
repo = git.Repo.init(path=temp_dir)
19-
blob = git.Blob(
20-
repo,
21-
**{
22-
"binsha": git.Blob.NULL_BIN_SHA,
23-
"path": fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes()),
24-
},
25-
)
19+
binsha = fdp.ConsumeBytes(20)
20+
mode = fdp.ConsumeInt(fdp.ConsumeIntInRange(0, fdp.remaining_bytes()))
21+
path = fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes())
22+
23+
try:
24+
blob = git.Blob(repo, binsha, mode, path)
25+
except AssertionError as e:
26+
if "Require 20 byte binary sha, got" in str(e):
27+
return -1
28+
else:
29+
raise e
2630

2731
_ = blob.mime_type
2832

0 commit comments

Comments
 (0)