-
-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1911 from DaveLak/add-blob-fuzz-target
Add git.Blob Fuzz Target
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"\\377\\377\\377\\377\\377\\377\\377\\377" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import atheris | ||
import sys | ||
import os | ||
import tempfile | ||
|
||
if getattr(sys, "frozen", False) and hasattr(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 | ||
|
||
with atheris.instrument_imports(): | ||
import git | ||
|
||
|
||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
repo = git.Repo.init(path=temp_dir) | ||
binsha = fdp.ConsumeBytes(20) | ||
mode = fdp.ConsumeInt(fdp.ConsumeIntInRange(0, fdp.remaining_bytes())) | ||
path = fdp.ConsumeUnicodeNoSurrogates(fdp.remaining_bytes()) | ||
|
||
try: | ||
blob = git.Blob(repo, binsha, mode, path) | ||
except AssertionError as e: | ||
if "Require 20 byte binary sha, got" in str(e): | ||
return -1 | ||
else: | ||
raise e | ||
|
||
_ = blob.mime_type | ||
|
||
|
||
def main(): | ||
atheris.Setup(sys.argv, TestOneInput) | ||
atheris.Fuzz() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |