Movatterモバイル変換


[0]ホーム

URL:


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

Commita915adf

Browse files
committed
AddDiff Fuzz Target
Adds a new `fuzz_diff.py` fuzz target that covers `Diff` classinitialization using fuzzed data.
1 parenta5815b6 commita915adf

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+
importsys
2+
importos
3+
importtempfile
4+
frombinasciiimportErrorasBinasciiError
5+
6+
importatheris
7+
8+
ifgetattr(sys,"frozen",False)andhasattr(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+
withatheris.instrument_imports():
13+
fromgitimportRepo,Diff
14+
15+
16+
defTestOneInput(data):
17+
fdp=atheris.FuzzedDataProvider(data)
18+
19+
withtempfile.TemporaryDirectory()astemp_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+
exceptBinasciiError:
40+
return-1
41+
exceptAssertionErrorase:
42+
if"Require 20 byte binary sha, got"instr(e):
43+
return-1
44+
else:
45+
raisee
46+
47+
48+
defmain():
49+
atheris.Setup(sys.argv,TestOneInput)
50+
atheris.Fuzz()
51+
52+
53+
if__name__=="__main__":
54+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp