mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-23 19:44:13 +03:00
I see a python file and I want to paint it black
This commit is contained in:
parent
6d6ef4a539
commit
c17ce801cf
|
@ -19,9 +19,9 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import atheris_no_libfuzzer as atheris
|
import atheris_no_libfuzzer as atheris
|
||||||
|
|
||||||
import fuzzers
|
import fuzzers
|
||||||
|
|
||||||
|
|
||||||
def TestOneInput(data):
|
def TestOneInput(data):
|
||||||
try:
|
try:
|
||||||
fuzzers.fuzz_font(data)
|
fuzzers.fuzz_font(data)
|
||||||
|
|
|
@ -18,9 +18,9 @@ import io
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import atheris_no_libfuzzer as atheris
|
||||||
import fuzzers
|
import fuzzers
|
||||||
|
|
||||||
import atheris_no_libfuzzer as atheris
|
|
||||||
|
|
||||||
def TestOneInput(data):
|
def TestOneInput(data):
|
||||||
try:
|
try:
|
||||||
|
@ -31,6 +31,7 @@ def TestOneInput(data):
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
fuzzers.enable_decompressionbomb_error()
|
fuzzers.enable_decompressionbomb_error()
|
||||||
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
|
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import warnings
|
|
||||||
import io
|
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():
|
def enable_decompressionbomb_error():
|
||||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
warnings.simplefilter("error", Image.DecompressionBombWarning)
|
warnings.simplefilter("error", Image.DecompressionBombWarning)
|
||||||
|
|
||||||
|
|
||||||
def fuzz_image(data):
|
def fuzz_image(data):
|
||||||
# This will fail on some images in the corpus, as we have many
|
# This will fail on some images in the corpus, as we have many
|
||||||
# invalid images in the test suite.
|
# invalid images in the test suite.
|
||||||
|
@ -16,6 +18,7 @@ def fuzz_image(data):
|
||||||
im.filter(ImageFilter.DETAIL)
|
im.filter(ImageFilter.DETAIL)
|
||||||
im.save(io.BytesIO(), "BMP")
|
im.save(io.BytesIO(), "BMP")
|
||||||
|
|
||||||
|
|
||||||
def fuzz_font(data):
|
def fuzz_font(data):
|
||||||
# This should not fail on a valid font load for any of the fonts in the corpus
|
# This should not fail on a valid font load for any of the fonts in the corpus
|
||||||
wrapper = io.BytesIO(data)
|
wrapper = io.BytesIO(data)
|
||||||
|
@ -30,4 +33,4 @@ def fuzz_font(data):
|
||||||
with Image.new(mode="RGBA", size=(200, 200)) as im:
|
with Image.new(mode="RGBA", size=(200, 200)) as im:
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
draw.multiline_textsize("ABC\nAaaa", font, stroke_width=2)
|
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")
|
||||||
|
|
|
@ -1,31 +1,40 @@
|
||||||
import pytest
|
|
||||||
|
|
||||||
import fuzzers
|
|
||||||
import glob
|
import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import fuzzers
|
||||||
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
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):
|
def test_fuzz_images(path):
|
||||||
fuzzers.enable_decompressionbomb_error()
|
fuzzers.enable_decompressionbomb_error()
|
||||||
try:
|
try:
|
||||||
with open(path, 'rb') as f:
|
with open(path, "rb") as f:
|
||||||
fuzzers.fuzz_image(f.read())
|
fuzzers.fuzz_image(f.read())
|
||||||
assert True
|
assert True
|
||||||
except (OSError, SyntaxError, MemoryError, ValueError, NotImplementedError):
|
except (OSError, SyntaxError, MemoryError, ValueError, NotImplementedError):
|
||||||
# Known exceptions that are through from Pillow
|
# Known exceptions that are through from Pillow
|
||||||
assert True
|
assert True
|
||||||
except (Image.DecompressionBombError, Image.DecompressionBombWarning,
|
except (
|
||||||
Image.UnidentifiedImageError):
|
Image.DecompressionBombError,
|
||||||
|
Image.DecompressionBombWarning,
|
||||||
|
Image.UnidentifiedImageError,
|
||||||
|
):
|
||||||
# Known Image.* exceptions
|
# Known Image.* exceptions
|
||||||
assert True
|
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):
|
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
|
return
|
||||||
with open(path, 'rb') as f:
|
with open(path, "rb") as f:
|
||||||
fuzzers.fuzz_font(f.read())
|
fuzzers.fuzz_font(f.read())
|
||||||
assert True
|
assert True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user