Skip to content

Commit f228d0c

Browse files
authored
Merge pull request #4102 from radarhere/decompression
Added decompression bomb checks
2 parents aaf2c42 + eed2bfc commit f228d0c

5 files changed

+11
-0
lines changed

Tests/images/decompression_bomb.gif

44 Bytes
Loading

Tests/images/decompression_bomb.ico

58 Bytes
Binary file not shown.

Tests/test_decompression_bomb.py

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def tearDown(self):
1414
def test_no_warning_small_file(self):
1515
# Implicit assert: no warning.
1616
# A warning would cause a failure.
17+
Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT
1718
Image.open(TEST_FILE)
1819

1920
def test_no_warning_no_limit(self):
@@ -41,6 +42,14 @@ def test_exception(self):
4142

4243
self.assertRaises(Image.DecompressionBombError, lambda: Image.open(TEST_FILE))
4344

45+
def test_exception_ico(self):
46+
with self.assertRaises(Image.DecompressionBombError):
47+
Image.open("Tests/images/decompression_bomb.ico")
48+
49+
def test_exception_gif(self):
50+
with self.assertRaises(Image.DecompressionBombError):
51+
Image.open("Tests/images/decompression_bomb.gif")
52+
4453

4554
class TestDecompressionCrop(PillowTestCase):
4655
def setUp(self):

src/PIL/GifImagePlugin.py

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def _seek(self, frame):
265265
self.dispose = None
266266
elif self.disposal_method == 2:
267267
# replace with background colour
268+
Image._decompression_bomb_check(self.size)
268269
self.dispose = Image.core.fill("P", self.size, self.info["background"])
269270
else:
270271
# replace with previous contents

src/PIL/IcoImagePlugin.py

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def frame(self, idx):
180180
else:
181181
# XOR + AND mask bmp frame
182182
im = BmpImagePlugin.DibImageFile(self.buf)
183+
Image._decompression_bomb_check(im.size)
183184

184185
# change tile dimension to only encompass XOR image
185186
im._size = (im.size[0], int(im.size[1] / 2))

0 commit comments

Comments
 (0)