Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a915adf

Browse files
committed
Add Diff Fuzz Target
Adds a new `fuzz_diff.py` fuzz target that covers `Diff` class initialization using fuzzed data.
1 parent a5815b6 commit a915adf

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎fuzzing/fuzz-targets/fuzz_diff.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import os
3+
import tempfile
4+
from binascii import Error as BinasciiError
5+
6+
import atheris
7+
8+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
9+
path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
10+
os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary
11+
12+
with atheris.instrument_imports():
13+
from git import Repo, Diff
14+
15+
16+
def TestOneInput(data):
17+
fdp = atheris.FuzzedDataProvider(data)
18+
19+
with tempfile.TemporaryDirectory() as temp_dir:
20+
repo = Repo.init(path=temp_dir)
21+
try:
22+
Diff(
23+
repo,
24+
a_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
25+
b_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
26+
a_blob_id=fdp.ConsumeBytes(20),
27+
b_blob_id=fdp.ConsumeBytes(20),
28+
a_mode=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
29+
b_mode=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
30+
new_file=fdp.ConsumeBool(),
31+
deleted_file=fdp.ConsumeBool(),
32+
copied_file=fdp.ConsumeBool(),
33+
raw_rename_from=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
34+
raw_rename_to=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
35+
diff=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
36+
change_type=fdp.PickValueInList(["A", "D", "C", "M", "R", "T", "U"]),
37+
score=fdp.ConsumeIntInRange(0, fdp.remaining_bytes()),
38+
)
39+
except BinasciiError:
40+
return -1
41+
except AssertionError as e:
42+
if "Require 20 byte binary sha, got" in str(e):
43+
return -1
44+
else:
45+
raise e
46+
47+
48+
def main():
49+
atheris.Setup(sys.argv, TestOneInput)
50+
atheris.Fuzz()
51+
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /