Skip to content

Commit 989ae1a

Browse files
committed
Read class properties & call methods to cover more features
Property access and private methods on the `Diff` class are complex and involve encoding and decoding operations that warrant being tested. This test borrows its design from the `test_diff.py` unit test file.
1 parent a915adf commit 989ae1a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Diff for: fuzzing/fuzz-targets/fuzz_diff.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import os
3+
import io
34
import tempfile
45
from binascii import Error as BinasciiError
56

@@ -13,13 +14,26 @@
1314
from git import Repo, Diff
1415

1516

17+
class BytesProcessAdapter:
18+
"""Allows bytes to be used as process objects returned by subprocess.Popen."""
19+
20+
def __init__(self, input_string):
21+
self.stdout = io.BytesIO(input_string)
22+
self.stderr = io.BytesIO()
23+
24+
def wait(self):
25+
return 0
26+
27+
poll = wait
28+
29+
1630
def TestOneInput(data):
1731
fdp = atheris.FuzzedDataProvider(data)
1832

1933
with tempfile.TemporaryDirectory() as temp_dir:
2034
repo = Repo.init(path=temp_dir)
2135
try:
22-
Diff(
36+
diff = Diff(
2337
repo,
2438
a_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
2539
b_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())),
@@ -44,6 +58,21 @@ def TestOneInput(data):
4458
else:
4559
raise e
4660

61+
_ = diff.__str__()
62+
_ = diff.a_path
63+
_ = diff.b_path
64+
_ = diff.rename_from
65+
_ = diff.rename_to
66+
_ = diff.renamed_file
67+
68+
diff_index = diff._index_from_patch_format(
69+
repo, proc=BytesProcessAdapter(fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())))
70+
)
71+
72+
diff._handle_diff_line(
73+
lines_bytes=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())), repo=repo, index=diff_index
74+
)
75+
4776

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

0 commit comments

Comments
 (0)