Skip to content

Commit 2a2294f

Browse files
committed
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.
1 parent 6c00ce6 commit 2a2294f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

fuzzing/fuzz-targets/fuzz_submodule.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
import tempfile
55
from configparser import ParsingError
66
from utils import is_expected_exception_message, get_max_filename_length
7+
from git import Repo, GitCommandError, InvalidGitRepositoryError
78

8-
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
9+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): # pragma: no cover
910
path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git"))
1011
os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary
1112

12-
with atheris.instrument_imports():
13-
from git import Repo, GitCommandError, InvalidGitRepositoryError
13+
if not sys.warnoptions: # pragma: no cover
14+
# The warnings filter below can be overridden by passing the -W option
15+
# to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
16+
import warnings
17+
import logging
18+
19+
# Fuzzing data causes some plugins to generate a large number of warnings
20+
# which are not usually interesting and make the test output hard to read, so we ignore them.
21+
warnings.simplefilter("ignore")
22+
logging.getLogger().setLevel(logging.ERROR)
1423

1524

1625
def TestOneInput(data):
@@ -92,6 +101,7 @@ def TestOneInput(data):
92101

93102

94103
def main():
104+
atheris.instrument_all()
95105
atheris.Setup(sys.argv, TestOneInput)
96106
atheris.Fuzz()
97107

fuzzing/fuzz-targets/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import atheris # pragma: no cover
2-
import os
2+
import os # pragma: no cover
33
from typing import List # pragma: no cover
44

55

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

2525

2626
@atheris.instrument_func
27-
def get_max_filename_length(path: str) -> int:
27+
def get_max_filename_length(path: str) -> int: # pragma: no cover
2828
"""
2929
Get the maximum filename length for the filesystem containing the given path.
3030

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy