Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Tests/test_file_spider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import struct
import tempfile
import warnings
from io import BytesIO
Expand Down Expand Up @@ -177,3 +178,22 @@ def test_odd_size() -> None:
data.seek(0)
with Image.open(data) as im2:
assert_image_equal(im, im2)


def test_seek_decompression_bomb() -> None:
with open(TEST_FILE, "rb") as fp:
data = fp.read()
# istack
first_frame = data[: 23 * 4] + struct.pack("<f", 1) + data[24 * 4 :]
# frame count
first_frame = first_frame[: 25 * 4] + struct.pack("<f", 2) + first_frame[26 * 4 :]

# width
second_frame = data[: 11 * 4] + struct.pack("<f", 65535) + data[12 * 4 :]
# height
second_frame = (
second_frame[: 1 * 4] + struct.pack("<f", 65535) + second_frame[2 * 4 :]
)
with Image.open(BytesIO(first_frame + b"\x00" * 1024 + second_frame)) as im:
with pytest.raises(Image.DecompressionBombError):
im.seek(1)
1 change: 1 addition & 0 deletions src/PIL/SpiderImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def seek(self, frame: int) -> None:
self.fp = self._fp
self.fp.seek(self.stkoffset)
self._open()
Image._decompression_bomb_check(self.size)

# returns a byte image after rescaling to 0..255
def convert2byte(self, depth: int = 255) -> Image.Image:
Expand Down
Loading