Merge pull request #8392 from radarhere/tiff_seek

Do not create core image in TIFF seek()
This commit is contained in:
Hugo van Kemenade 2024-10-12 11:46:36 +03:00 committed by GitHub
commit 686b5e2cb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1193,11 +1193,11 @@ class TiffImageFile(ImageFile.ImageFile):
if not self._seek_check(frame): if not self._seek_check(frame):
return return
self._seek(frame) self._seek(frame)
# Create a new core image object on second and if self._im is not None and (
# subsequent frames in the image. Image may be self.im.size != self._tile_size or self.im.mode != self.mode
# different size/mode. ):
Image._decompression_bomb_check(self._tile_size) # The core image will no longer be used
self.im = Image.core.new(self.mode, self._tile_size) self._im = None
def _seek(self, frame: int) -> None: def _seek(self, frame: int) -> None:
self.fp = self._fp self.fp = self._fp
@ -1279,6 +1279,7 @@ class TiffImageFile(ImageFile.ImageFile):
def load_prepare(self) -> None: def load_prepare(self) -> None:
if self._im is None: if self._im is None:
Image._decompression_bomb_check(self._tile_size)
self.im = Image.core.new(self.mode, self._tile_size) self.im = Image.core.new(self.mode, self._tile_size)
ImageFile.ImageFile.load_prepare(self) ImageFile.ImageFile.load_prepare(self)