Clear core image if memory mapping was used for last load

This commit is contained in:
Andrew Murray 2025-05-25 15:00:47 +10:00
parent 7e4d8e2f55
commit 041acf1344
2 changed files with 17 additions and 2 deletions

View File

@ -52,3 +52,17 @@ def test_tiff_crashes(test_file: str) -> None:
pytest.skip("test image not found")
except OSError:
pass
def test_tiff_mmap() -> None:
try:
with Image.open("Tests/images/crash_mmap.tif") as im:
im.seek(1)
im.load()
im.seek(0)
im.load()
except FileNotFoundError:
if on_ci():
raise
pytest.skip("test image not found")

View File

@ -1217,9 +1217,10 @@ class TiffImageFile(ImageFile.ImageFile):
return
self._seek(frame)
if self._im is not None and (
self.im.size != self._tile_size or self.im.mode != self.mode
self.im.size != self._tile_size
or self.im.mode != self.mode
or self.readonly
):
# The core image will no longer be used
self._im = None
def _seek(self, frame: int) -> None: