mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-01 03:33:21 +03:00
Added type hints
This commit is contained in:
parent
c23904a4bd
commit
81b5c5dc68
|
@ -158,7 +158,7 @@ def assert_tuple_approx_equal(actuals, targets, threshold, msg):
|
||||||
assert value, msg + ": " + repr(actuals) + " != " + repr(targets)
|
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"
|
reason = f"{feature} not available"
|
||||||
return pytest.mark.skipif(not features.check(feature), reason=reason)
|
return pytest.mark.skipif(not features.check(feature), reason=reason)
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ with atheris.instrument_imports():
|
||||||
import fuzzers
|
import fuzzers
|
||||||
|
|
||||||
|
|
||||||
def TestOneInput(data):
|
def TestOneInput(data: bytes) -> None:
|
||||||
try:
|
try:
|
||||||
fuzzers.fuzz_font(data)
|
fuzzers.fuzz_font(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -32,7 +32,7 @@ def TestOneInput(data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> None:
|
||||||
fuzzers.enable_decompressionbomb_error()
|
fuzzers.enable_decompressionbomb_error()
|
||||||
atheris.Setup(sys.argv, TestOneInput)
|
atheris.Setup(sys.argv, TestOneInput)
|
||||||
atheris.Fuzz()
|
atheris.Fuzz()
|
||||||
|
|
|
@ -23,7 +23,7 @@ with atheris.instrument_imports():
|
||||||
import fuzzers
|
import fuzzers
|
||||||
|
|
||||||
|
|
||||||
def TestOneInput(data):
|
def TestOneInput(data: bytes) -> None:
|
||||||
try:
|
try:
|
||||||
fuzzers.fuzz_image(data)
|
fuzzers.fuzz_image(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -32,7 +32,7 @@ def TestOneInput(data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main() -> None:
|
||||||
fuzzers.enable_decompressionbomb_error()
|
fuzzers.enable_decompressionbomb_error()
|
||||||
atheris.Setup(sys.argv, TestOneInput)
|
atheris.Setup(sys.argv, TestOneInput)
|
||||||
atheris.Fuzz()
|
atheris.Fuzz()
|
||||||
|
|
|
@ -5,18 +5,18 @@ import warnings
|
||||||
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont
|
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont
|
||||||
|
|
||||||
|
|
||||||
def enable_decompressionbomb_error():
|
def enable_decompressionbomb_error() -> None:
|
||||||
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 disable_decompressionbomb_error():
|
def disable_decompressionbomb_error() -> None:
|
||||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
warnings.resetwarnings()
|
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
|
# 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.
|
||||||
with Image.open(io.BytesIO(data)) as im:
|
with Image.open(io.BytesIO(data)) as im:
|
||||||
|
@ -25,7 +25,7 @@ def fuzz_image(data):
|
||||||
im.save(io.BytesIO(), "BMP")
|
im.save(io.BytesIO(), "BMP")
|
||||||
|
|
||||||
|
|
||||||
def fuzz_font(data):
|
def fuzz_font(data: bytes) -> None:
|
||||||
wrapper = io.BytesIO(data)
|
wrapper = io.BytesIO(data)
|
||||||
try:
|
try:
|
||||||
font = ImageFont.truetype(wrapper)
|
font = ImageFont.truetype(wrapper)
|
||||||
|
|
|
@ -23,7 +23,7 @@ if features.check("libjpeg_turbo"):
|
||||||
"path",
|
"path",
|
||||||
subprocess.check_output("find Tests/images -type f", shell=True).split(b"\n"),
|
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()
|
fuzzers.enable_decompressionbomb_error()
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
|
@ -54,7 +54,7 @@ def test_fuzz_images(path):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path", subprocess.check_output("find Tests/fonts -type f", shell=True).split(b"\n")
|
"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:
|
if not path:
|
||||||
return
|
return
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user