|
| 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() |