This commit is contained in:
Hugo 2016-08-31 07:00:08 +00:00 committed by GitHub
commit 157536a75d
2 changed files with 14 additions and 0 deletions

View File

@ -2033,6 +2033,8 @@ def new(mode, size, color=0):
:returns: An :py:class:`~PIL.Image.Image` object.
"""
_decompression_bomb_check(size)
if color is None:
# don't initialize
return Image()._new(core.new(mode, size))

View File

@ -39,5 +39,17 @@ class TestDecompressionBomb(PillowTestCase):
Image.DecompressionBombWarning,
lambda: Image.open(TEST_FILE))
def test_image_new(self):
# Arrange
# Set limit to a low, easily testable value
Image.MAX_IMAGE_PIXELS = 10
self.assertEqual(Image.MAX_IMAGE_PIXELS, 10)
# Act / Assert
self.assert_warning(
Image.DecompressionBombWarning,
lambda: Image.new('L', (100, 100), 0))
if __name__ == '__main__':
unittest.main()