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
14 changes: 14 additions & 0 deletions Tests/test_tiff_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@
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

Check warning on line 67 in Tests/test_tiff_crashes.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_tiff_crashes.py#L67

Added line #L67 was not covered by tests
pytest.skip("test image not found")
5 changes: 3 additions & 2 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,10 @@ def seek(self, frame: int) -> None:
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:
Expand Down
1 change: 1 addition & 0 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
}
}

im->read_only = view.readonly;
im->destroy = mapping_destroy_buffer;

Py_INCREF(target);
Expand Down
Loading