Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork966
Expand file tree
/
Copy pathfuzz_diff.py
More file actions
86 lines (68 loc) · 2.82 KB
/
fuzz_diff.py
File metadata and controls
86 lines (68 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
importsys
importos
importio
importtempfile
frombinasciiimportErrorasBinasciiError
importatheris
ifgetattr(sys,"frozen",False)andhasattr(sys,"_MEIPASS"):
path_to_bundled_git_binary=os.path.abspath(os.path.join(os.path.dirname(__file__),"git"))
os.environ["GIT_PYTHON_GIT_EXECUTABLE"]=path_to_bundled_git_binary
withatheris.instrument_imports():
fromgitimportRepo,Diff
classBytesProcessAdapter:
"""Allows bytes to be used as process objects returned by subprocess.Popen."""
@atheris.instrument_func
def__init__(self,input_string):
self.stdout=io.BytesIO(input_string)
self.stderr=io.BytesIO()
@atheris.instrument_func
defwait(self):
return0
poll=wait
@atheris.instrument_func
defTestOneInput(data):
fdp=atheris.FuzzedDataProvider(data)
withtempfile.TemporaryDirectory()astemp_dir:
repo=Repo.init(path=temp_dir)
try:
diff=Diff(
repo,
a_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
b_rawpath=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
a_blob_id=fdp.ConsumeBytes(20),
b_blob_id=fdp.ConsumeBytes(20),
a_mode=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
b_mode=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
new_file=fdp.ConsumeBool(),
deleted_file=fdp.ConsumeBool(),
copied_file=fdp.ConsumeBool(),
raw_rename_from=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
raw_rename_to=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
diff=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),
change_type=fdp.PickValueInList(["A","D","C","M","R","T","U"]),
score=fdp.ConsumeIntInRange(0,fdp.remaining_bytes()),
)
exceptBinasciiError:
return-1
exceptAssertionErrorase:
if"Require 20 byte binary sha, got"instr(e):
return-1
else:
raisee
_=diff.__str__()
_=diff.a_path
_=diff.b_path
_=diff.rename_from
_=diff.rename_to
_=diff.renamed_file
diff_index=diff._index_from_patch_format(
repo,proc=BytesProcessAdapter(fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())))
)
diff._handle_diff_line(
lines_bytes=fdp.ConsumeBytes(fdp.ConsumeIntInRange(0,fdp.remaining_bytes())),repo=repo,index=diff_index
)
defmain():
atheris.Setup(sys.argv,TestOneInput)
atheris.Fuzz()
if__name__=="__main__":
main()