mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Test decompression bomb warnings
This commit is contained in:
parent
b853696ad5
commit
fd05e9c756
|
@ -2104,7 +2104,7 @@ _fromarray_typemap[((1, 1), _ENDIAN + "i4")] = ("I", "I")
|
||||||
_fromarray_typemap[((1, 1), _ENDIAN + "f4")] = ("F", "F")
|
_fromarray_typemap[((1, 1), _ENDIAN + "f4")] = ("F", "F")
|
||||||
|
|
||||||
|
|
||||||
def _compression_bomb_check(size):
|
def _decompression_bomb_check(size):
|
||||||
if MAX_IMAGE_PIXELS is None:
|
if MAX_IMAGE_PIXELS is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -2157,7 +2157,7 @@ def open(fp, mode="r"):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
# return factory(fp, filename)
|
# return factory(fp, filename)
|
||||||
im = factory(fp, filename)
|
im = factory(fp, filename)
|
||||||
_compression_bomb_check(im.size)
|
_decompression_bomb_check(im.size)
|
||||||
return im
|
return im
|
||||||
except (SyntaxError, IndexError, TypeError):
|
except (SyntaxError, IndexError, TypeError):
|
||||||
#import traceback
|
#import traceback
|
||||||
|
@ -2173,7 +2173,7 @@ def open(fp, mode="r"):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
# return factory(fp, filename)
|
# return factory(fp, filename)
|
||||||
im = factory(fp, filename)
|
im = factory(fp, filename)
|
||||||
_compression_bomb_check(im.size)
|
_decompression_bomb_check(im.size)
|
||||||
return im
|
return im
|
||||||
except (SyntaxError, IndexError, TypeError):
|
except (SyntaxError, IndexError, TypeError):
|
||||||
#import traceback
|
#import traceback
|
||||||
|
|
37
Tests/test_decompression_bomb.py
Normal file
37
Tests/test_decompression_bomb.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from tester import *
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
test_file = "Images/lena.ppm"
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_warning_small_file():
|
||||||
|
# Implicit assert: no warning.
|
||||||
|
# A warning would cause a failure.
|
||||||
|
Image.open(test_file)
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_warning_no_limit():
|
||||||
|
# Arrange
|
||||||
|
# Turn limit off
|
||||||
|
Image.MAX_IMAGE_PIXELS = None
|
||||||
|
assert_equal(Image.MAX_IMAGE_PIXELS, None)
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
# Implicit assert: no warning.
|
||||||
|
# A warning would cause a failure.
|
||||||
|
Image.open(test_file)
|
||||||
|
|
||||||
|
|
||||||
|
def test_warning():
|
||||||
|
# Arrange
|
||||||
|
# Set limit to a low, easily testable value
|
||||||
|
Image.MAX_IMAGE_PIXELS = 10
|
||||||
|
assert_equal(Image.MAX_IMAGE_PIXELS, 10)
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
assert_warning(
|
||||||
|
RuntimeWarning,
|
||||||
|
lambda: Image.open(test_file))
|
||||||
|
|
||||||
|
# End of file
|
Loading…
Reference in New Issue
Block a user