Skip to content
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

Added type hints to OSS Fuzz scripts #7731

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def assert_tuple_approx_equal(actuals, targets, threshold, msg):
assert value, msg + ": " + repr(actuals) + " != " + repr(targets)


def skip_unless_feature(feature):
def skip_unless_feature(feature: str) -> pytest.MarkDecorator:
reason = f"{feature} not available"
return pytest.mark.skipif(not features.check(feature), reason=reason)

Expand Down
4 changes: 2 additions & 2 deletions Tests/oss-fuzz/fuzz_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import fuzzers


def TestOneInput(data):
def TestOneInput(data: bytes) -> None:
try:
fuzzers.fuzz_font(data)
except Exception:
Expand All @@ -32,7 +32,7 @@ def TestOneInput(data):
pass


def main():
def main() -> None:
fuzzers.enable_decompressionbomb_error()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
Expand Down
4 changes: 2 additions & 2 deletions Tests/oss-fuzz/fuzz_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import fuzzers


def TestOneInput(data):
def TestOneInput(data: bytes) -> None:
try:
fuzzers.fuzz_image(data)
except Exception:
Expand All @@ -32,7 +32,7 @@ def TestOneInput(data):
pass


def main():
def main() -> None:
fuzzers.enable_decompressionbomb_error()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
Expand Down
8 changes: 4 additions & 4 deletions Tests/oss-fuzz/fuzzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont


def enable_decompressionbomb_error():
def enable_decompressionbomb_error() -> None:
ImageFile.LOAD_TRUNCATED_IMAGES = True
warnings.filterwarnings("ignore")
warnings.simplefilter("error", Image.DecompressionBombWarning)


def disable_decompressionbomb_error():
def disable_decompressionbomb_error() -> None:
ImageFile.LOAD_TRUNCATED_IMAGES = False
warnings.resetwarnings()


def fuzz_image(data):
def fuzz_image(data: bytes) -> None:
# This will fail on some images in the corpus, as we have many
# invalid images in the test suite.
with Image.open(io.BytesIO(data)) as im:
Expand All @@ -25,7 +25,7 @@ def fuzz_image(data):
im.save(io.BytesIO(), "BMP")


def fuzz_font(data):
def fuzz_font(data: bytes) -> None:
wrapper = io.BytesIO(data)
try:
font = ImageFont.truetype(wrapper)
Expand Down
4 changes: 2 additions & 2 deletions Tests/oss-fuzz/test_fuzzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"path",
subprocess.check_output("find Tests/images -type f", shell=True).split(b"\n"),
)
def test_fuzz_images(path):
def test_fuzz_images(path: str) -> None:
fuzzers.enable_decompressionbomb_error()
try:
with open(path, "rb") as f:
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_fuzz_images(path):
@pytest.mark.parametrize(
"path", subprocess.check_output("find Tests/fonts -type f", shell=True).split(b"\n")
)
def test_fuzz_fonts(path):
def test_fuzz_fonts(path: str) -> None:
if not path:
return
with open(path, "rb") as f:
Expand Down
Loading