Skip to content

Add graceful handling of expected exceptions in fuzz_submodule.py #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve fuzz_submodule.py coverage & efficacy
The fuzzer was having trouble analyzing `fuzz_submodule.py` when using
the `atheris.instrument_imports()` context manager. Switching to
`atheris.instrument_all()` instead slightly increases the startup time
for the fuzzer, but significantly improves the fuzzing engines ability
to identify new coverage.

The changes here also disable warnings that are logged to `stdout` from
the SUT. These warnings are expected to happen with some inputs and
clutter the fuzzer output logs. They can be optionally re-enabled for
debugging by passing a flag o the Python interpreter command line or
setting the `PYTHONWARNINGS` environment variable.
  • Loading branch information
DaveLak committed May 30, 2024
commit 2a2294f9d1e46d9bbe11cd2031d62e5441fe19c4
16 changes: 13 additions & 3 deletions fuzzing/fuzz-targets/fuzz_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
import tempfile
from configparser import ParsingError
from utils import is_expected_exception_message, get_max_filename_length
from git import Repo, GitCommandError, InvalidGitRepositoryError

if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): # pragma: no cover
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():
from git import Repo, GitCommandError, InvalidGitRepositoryError
if not sys.warnoptions: # pragma: no cover
# The warnings filter below can be overridden by passing the -W option
# to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
import warnings
import logging

# Fuzzing data causes some plugins to generate a large number of warnings
# which are not usually interesting and make the test output hard to read, so we ignore them.
warnings.simplefilter("ignore")
logging.getLogger().setLevel(logging.ERROR)


def TestOneInput(data):
Expand Down Expand Up @@ -92,6 +101,7 @@ def TestOneInput(data):


def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()

Expand Down
4 changes: 2 additions & 2 deletions fuzzing/fuzz-targets/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import atheris # pragma: no cover
import os
import os # pragma: no cover
from typing import List # pragma: no cover


Expand All @@ -24,7 +24,7 @@ def is_expected_exception_message(exception: Exception, error_message_list: List


@atheris.instrument_func
def get_max_filename_length(path: str) -> int:
def get_max_filename_length(path: str) -> int: # pragma: no cover
"""
Get the maximum filename length for the filesystem containing the given path.
Expand Down