Coverage for /pythoncovmergedfiles/medio/medio/src/dulwich/fuzzing/fuzz-targets/fuzz_object_store.py: 68%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12import stat
13import sys
14from io import BytesIO
16import atheris
18with atheris.instrument_imports():
19 # We instrument `test_utils` as well, so it doesn't block coverage analysis in Fuzz Introspector:
20 from test_utils import EnhancedFuzzedDataProvider, is_expected_exception
22 from dulwich.errors import ObjectFormatException
23 from dulwich.objects import S_IFGITLINK, Blob, Commit, Tree
24 from dulwich.patch import write_tree_diff
25 from dulwich.repo import (
26 InvalidUserIdentity,
27 MemoryRepo,
28 )
31def TestOneInput(data):
32 fdp = EnhancedFuzzedDataProvider(data)
33 repo = MemoryRepo()
34 blob = Blob.from_string(fdp.ConsumeRandomBytes())
35 tree = Tree()
36 tree.add(
37 fdp.ConsumeRandomBytes(),
38 fdp.PickValueInList([stat.S_IFREG, stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK]),
39 blob.id,
40 )
41 commit = Commit()
42 commit.tree = tree.id
43 commit.author = fdp.ConsumeRandomBytes()
44 commit.committer = fdp.ConsumeRandomBytes()
45 commit.commit_time = fdp.ConsumeRandomInt()
46 commit.commit_timezone = fdp.ConsumeRandomInt()
47 commit.author_time = fdp.ConsumeRandomInt()
48 commit.author_timezone = fdp.ConsumeRandomInt()
49 commit.message = fdp.ConsumeRandomBytes()
51 object_store = repo.object_store
53 try:
54 object_store.add_object(blob)
55 object_store.add_object(tree)
56 object_store.add_object(commit)
57 except (InvalidUserIdentity, ObjectFormatException):
58 return -1
59 except ValueError as e:
60 expected_exceptions = [
61 "subsection not found",
62 "Unable to handle non-minute offset",
63 ]
64 if is_expected_exception(expected_exceptions, e):
65 return -1
66 else:
67 raise e
69 commit2 = Commit()
70 commit2.tree = tree.id
71 commit2.parents = [commit.id]
72 commit2.author = commit.author
73 commit2.committer = commit.committer
74 commit2.commit_time = fdp.ConsumeRandomInt()
75 commit2.commit_timezone = fdp.ConsumeRandomInt()
76 commit2.author_time = fdp.ConsumeRandomInt()
77 commit2.author_timezone = fdp.ConsumeRandomInt()
78 commit2.message = fdp.ConsumeRandomBytes()
80 try:
81 blob.data = fdp.ConsumeRandomBytes()
82 repo.object_store.add_object(blob)
83 repo.object_store.add_object(tree)
84 repo.object_store.add_object(commit2)
85 out = BytesIO()
86 write_tree_diff(out, repo.object_store, commit.tree, tree.id)
87 except (InvalidUserIdentity, ObjectFormatException):
88 return -1
89 except ValueError as e:
90 expected_exceptions = [
91 "Unable to handle non-minute offset",
92 ]
93 if is_expected_exception(expected_exceptions, e):
94 return -1
95 else:
96 raise e
99def main():
100 atheris.Setup(sys.argv, TestOneInput)
101 atheris.Fuzz()
104if __name__ == "__main__":
105 main()