I see a python file and I want to paint it black

This commit is contained in:
Eric Soroos 2021-03-14 13:02:48 +01:00
parent 6d6ef4a539
commit c17ce801cf
4 changed files with 28 additions and 15 deletions

View File

@ -19,9 +19,9 @@ import sys
import warnings
import atheris_no_libfuzzer as atheris
import fuzzers
def TestOneInput(data):
try:
fuzzers.fuzz_font(data)

View File

@ -18,9 +18,9 @@ import io
import sys
import warnings
import atheris_no_libfuzzer as atheris
import fuzzers
import atheris_no_libfuzzer as atheris
def TestOneInput(data):
try:
@ -31,6 +31,7 @@ def TestOneInput(data):
return
return
def main():
fuzzers.enable_decompressionbomb_error()
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)

View File

@ -1,13 +1,15 @@
import warnings
import io
import warnings
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont, PcfFontFile
from PIL import Image, ImageFont, ImageDraw, ImageFilter, ImageFile, PcfFontFile
def enable_decompressionbomb_error():
ImageFile.LOAD_TRUNCATED_IMAGES = True
warnings.filterwarnings("ignore")
warnings.simplefilter("error", Image.DecompressionBombWarning)
def fuzz_image(data):
# This will fail on some images in the corpus, as we have many
# invalid images in the test suite.
@ -16,6 +18,7 @@ def fuzz_image(data):
im.filter(ImageFilter.DETAIL)
im.save(io.BytesIO(), "BMP")
def fuzz_font(data):
# This should not fail on a valid font load for any of the fonts in the corpus
wrapper = io.BytesIO(data)
@ -30,4 +33,4 @@ def fuzz_font(data):
with Image.new(mode="RGBA", size=(200, 200)) as im:
draw = ImageDraw.Draw(im)
draw.multiline_textsize("ABC\nAaaa", font, stroke_width=2)
draw.text((10,10), "Test Text", font=font, fill="#000")
draw.text((10, 10), "Test Text", font=font, fill="#000")

View File

@ -1,31 +1,40 @@
import pytest
import fuzzers
import glob
import subprocess
import fuzzers
import pytest
from PIL import Image
@pytest.mark.parametrize("path", subprocess.check_output('find Tests/images -type f', shell=True).split(b'\n'))
@pytest.mark.parametrize(
"path",
subprocess.check_output("find Tests/images -type f", shell=True).split(b"\n"),
)
def test_fuzz_images(path):
fuzzers.enable_decompressionbomb_error()
try:
with open(path, 'rb') as f:
with open(path, "rb") as f:
fuzzers.fuzz_image(f.read())
assert True
except (OSError, SyntaxError, MemoryError, ValueError, NotImplementedError):
# Known exceptions that are through from Pillow
assert True
except (Image.DecompressionBombError, Image.DecompressionBombWarning,
Image.UnidentifiedImageError):
except (
Image.DecompressionBombError,
Image.DecompressionBombWarning,
Image.UnidentifiedImageError,
):
# Known Image.* exceptions
assert True
@pytest.mark.parametrize("path", subprocess.check_output('find Tests/fonts -type f', shell=True).split(b'\n'))
@pytest.mark.parametrize(
"path", subprocess.check_output("find Tests/fonts -type f", shell=True).split(b"\n")
)
def test_fuzz_fonts(path):
if not path or b'LICENSE.txt' in path or b'.pil' in path:
if not path or b"LICENSE.txt" in path or b".pil" in path:
return
with open(path, 'rb') as f:
with open(path, "rb") as f:
fuzzers.fuzz_font(f.read())
assert True