diff --git a/Tests/images/decompression_bomb.gif b/Tests/images/decompression_bomb.gif new file mode 100644 index 00000000000..3ca21b60a97 Binary files /dev/null and b/Tests/images/decompression_bomb.gif differ diff --git a/Tests/images/decompression_bomb.ico b/Tests/images/decompression_bomb.ico new file mode 100644 index 00000000000..0efc9eaf74b Binary files /dev/null and b/Tests/images/decompression_bomb.ico differ diff --git a/Tests/test_decompression_bomb.py b/Tests/test_decompression_bomb.py index b3a36fe7870..7c18f85d245 100644 --- a/Tests/test_decompression_bomb.py +++ b/Tests/test_decompression_bomb.py @@ -14,6 +14,7 @@ def tearDown(self): def test_no_warning_small_file(self): # Implicit assert: no warning. # A warning would cause a failure. + Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT Image.open(TEST_FILE) def test_no_warning_no_limit(self): @@ -41,6 +42,14 @@ def test_exception(self): self.assertRaises(Image.DecompressionBombError, lambda: Image.open(TEST_FILE)) + def test_exception_ico(self): + with self.assertRaises(Image.DecompressionBombError): + Image.open("Tests/images/decompression_bomb.ico") + + def test_exception_gif(self): + with self.assertRaises(Image.DecompressionBombError): + Image.open("Tests/images/decompression_bomb.gif") + class TestDecompressionCrop(PillowTestCase): def setUp(self): diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 07f5ab6832d..9d8e96feeeb 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -265,6 +265,7 @@ def _seek(self, frame): self.dispose = None elif self.disposal_method == 2: # replace with background colour + Image._decompression_bomb_check(self.size) self.dispose = Image.core.fill("P", self.size, self.info["background"]) else: # replace with previous contents diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index fc728d6fbd5..148e604f895 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -180,6 +180,7 @@ def frame(self, idx): else: # XOR + AND mask bmp frame im = BmpImagePlugin.DibImageFile(self.buf) + Image._decompression_bomb_check(im.size) # change tile dimension to only encompass XOR image im._size = (im.size[0], int(im.size[1] / 2))