Coverage for /pythoncovmergedfiles/medio/medio/src/gitpython/fuzzing/fuzz-targets/fuzz_blob.py: 42%
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 atheris
13import sys
14import os
15import tempfile
17if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
18 path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
19 os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary
21with atheris.instrument_imports():
22 import git
25def TestOneInput(data):
26 fdp = atheris.FuzzedDataProvider(data)
28 with tempfile.TemporaryDirectory() as temp_dir:
29 repo = git.Repo.init(path=temp_dir)
30 binsha = fdp.ConsumeBytes(20)
31 mode = fdp.ConsumeInt(fdp.ConsumeIntInRange(0, fdp.remaining_bytes()))
32 path = fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes())
34 try:
35 blob = git.Blob(repo, binsha, mode, path)
36 except AssertionError as e:
37 if "Require 20 byte binary sha, got" in str(e):
38 return -1
39 else:
40 raise e
42 _ = blob.mime_type
45def main():
46 atheris.Setup(sys.argv, TestOneInput)
47 atheris.Fuzz()
50if __name__ == "__main__":
51 main()