Skip to content

Commit e23f017

Browse files
authored
Allow loading ImageFile state from Pillow < 11.2.1 (#8938)
2 parents c2f1b98 + 47bebfc commit e23f017

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Tests/test_pickle.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,13 @@ def test_pickle_font_file(tmp_path: Path, protocol: int) -> None:
162162

163163
# Assert
164164
helper_assert_pickled_font_images(font, unpickled_font)
165+
166+
167+
def test_load_earlier_data() -> None:
168+
im = pickle.loads(
169+
b"\x80\x04\x95@\x00\x00\x00\x00\x00\x00\x00\x8c\x12PIL.PngImagePlugin"
170+
b"\x94\x8c\x0cPngImageFile\x94\x93\x94)\x81\x94]\x94(}\x94\x8c\x01L\x94K\x01"
171+
b"K\x01\x86\x94NC\x01\x00\x94eb."
172+
)
173+
assert im.mode == "L"
174+
assert im.size == (1, 1)

src/PIL/ImageFile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ def __getstate__(self) -> list[Any]:
257257

258258
def __setstate__(self, state: list[Any]) -> None:
259259
self.tile = []
260-
self.filename = state[5]
260+
if len(state) > 5:
261+
self.filename = state[5]
261262
super().__setstate__(state)
262263

263264
def verify(self) -> None:

0 commit comments

Comments
 (0)