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

‎fuzzing/fuzz-targets/fuzz_diff.py‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importsys
22
importos
3+
importio
34
importtempfile
45
frombinasciiimportErrorasBinasciiError
56

@@ -13,13 +14,26 @@
1314
fromgitimportRepo, Diff
1415

1516

17+
classBytesProcessAdapter:
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+
defwait(self):
25+
return0
26+
27+
poll=wait
28+
29+
1630
defTestOneInput(data):
1731
fdp=atheris.FuzzedDataProvider(data)
1832

1933
withtempfile.TemporaryDirectory() astemp_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
raisee
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
defmain():
4978
atheris.Setup(sys.argv, TestOneInput)

0 commit comments

Comments
(0)