2021-03-14 14:21:02 +03:00
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
|
2021-03-14 15:02:48 +03:00
|
|
|
import fuzzers
|
|
|
|
import pytest
|
|
|
|
|
2021-03-14 14:21:02 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2021-03-14 15:02:48 +03:00
|
|
|
|
|
|
|
@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:
|
2021-03-14 15:02:48 +03:00
|
|
|
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):
|
|
|
|
# Known exceptions that are through from Pillow
|
|
|
|
assert True
|
2021-03-14 15:02:48 +03:00
|
|
|
except (
|
|
|
|
Image.DecompressionBombError,
|
|
|
|
Image.DecompressionBombWarning,
|
|
|
|
Image.UnidentifiedImageError,
|
|
|
|
):
|
2021-03-14 14:21:02 +03:00
|
|
|
# Known Image.* exceptions
|
|
|
|
assert True
|
|
|
|
|
|
|
|
|
2021-03-14 15:02:48 +03:00
|
|
|
@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-14 15:02:48 +03:00
|
|
|
if not path or b"LICENSE.txt" in path or b".pil" in path:
|
2021-03-14 14:21:02 +03:00
|
|
|
return
|
2021-03-14 15:02:48 +03:00
|
|
|
with open(path, "rb") as f:
|
2021-03-14 14:21:02 +03:00
|
|
|
fuzzers.fuzz_font(f.read())
|
|
|
|
assert True
|