Pillow/Tests/oss-fuzz/test_fuzzers.py

54 lines
1.3 KiB
Python
Raw Normal View History

2021-03-14 14:21:02 +03:00
import subprocess
2021-03-14 15:27:47 +03:00
import sys
2021-03-14 14:21:02 +03:00
import fuzzers
import pytest
2021-03-14 14:21:02 +03:00
from PIL import Image
if sys.platform.startswith("win32"):
pytest.skip("Fuzzer is linux only", allow_module_level=True)
@pytest.mark.parametrize(
"path",
subprocess.check_output("find Tests/images -type f", shell=True).split(b"\n"),
)
2021-03-14 14:21:02 +03:00
def test_fuzz_images(path):
fuzzers.enable_decompressionbomb_error()
try:
with open(path, "rb") as f:
2021-03-14 14:21:02 +03:00
fuzzers.fuzz_image(f.read())
assert True
except (
OSError,
SyntaxError,
MemoryError,
ValueError,
NotImplementedError,
OverflowError,
):
2021-03-14 14:21:02 +03:00
# Known exceptions that are through from Pillow
assert True
except (
Image.DecompressionBombError,
Image.DecompressionBombWarning,
Image.UnidentifiedImageError,
):
2021-03-14 14:21:02 +03:00
# Known Image.* exceptions
assert True
@pytest.mark.parametrize(
"path", subprocess.check_output("find Tests/fonts -type f", shell=True).split(b"\n")
)
2021-03-14 14:21:02 +03:00
def test_fuzz_fonts(path):
2021-03-15 02:18:07 +03:00
if not path:
2021-03-14 14:21:02 +03:00
return
with open(path, "rb") as f:
try:
fuzzers.fuzz_font(f.read())
2021-03-17 15:16:35 +03:00
except (Image.DecompressionBombError, Image.DecompressionBombWarning):
pass
2021-03-14 14:21:02 +03:00
assert True