diff --git a/PIL/Image.py b/PIL/Image.py index 8a4aa6ae6..c9180600d 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -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)) diff --git a/Tests/test_decompression_bomb.py b/Tests/test_decompression_bomb.py index e952f6586..c75663251 100644 --- a/Tests/test_decompression_bomb.py +++ b/Tests/test_decompression_bomb.py @@ -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()