Skip to content

Commit 041acf1

Browse files
committed
Clear core image if memory mapping was used for last load
1 parent 7e4d8e2 commit 041acf1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Tests/test_tiff_crashes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@ def test_tiff_crashes(test_file: str) -> None:
5252
pytest.skip("test image not found")
5353
except OSError:
5454
pass
55+
56+
57+
def test_tiff_mmap() -> None:
58+
try:
59+
with Image.open("Tests/images/crash_mmap.tif") as im:
60+
im.seek(1)
61+
im.load()
62+
63+
im.seek(0)
64+
im.load()
65+
except FileNotFoundError:
66+
if on_ci():
67+
raise
68+
pytest.skip("test image not found")

src/PIL/TiffImagePlugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,10 @@ def seek(self, frame: int) -> None:
12171217
return
12181218
self._seek(frame)
12191219
if self._im is not None and (
1220-
self.im.size != self._tile_size or self.im.mode != self.mode
1220+
self.im.size != self._tile_size
1221+
or self.im.mode != self.mode
1222+
or self.readonly
12211223
):
1222-
# The core image will no longer be used
12231224
self._im = None
12241225

12251226
def _seek(self, frame: int) -> None:

0 commit comments

Comments
 (0)