Avoid DecompressionBombWarning: Image size (151587072 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack.

This commit is contained in:
Hugo van Kemenade 2021-08-24 11:19:45 +03:00
parent 474270fbd5
commit 320ab8172e

View File

@ -24,11 +24,17 @@ def test_overflow():
def test_tobytes(): def test_tobytes():
# Note that this image triggers the decompression bomb warning:
max_pixels = Image.MAX_IMAGE_PIXELS
Image.MAX_IMAGE_PIXELS = None
# Previously raised an access violation on Windows # Previously raised an access violation on Windows
with Image.open("Tests/images/l2rgb_read.bmp") as im: with Image.open("Tests/images/l2rgb_read.bmp") as im:
with pytest.raises((ValueError, MemoryError, OSError)): with pytest.raises((ValueError, MemoryError, OSError)):
im.tobytes() im.tobytes()
Image.MAX_IMAGE_PIXELS = max_pixels
@pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system") @pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system")
def test_ysize(): def test_ysize():