Do not create core image in seek(), when load() might not run

This commit is contained in:
Andrew Murray 2024-09-19 09:24:04 +10:00
parent 1ee3bd1d9e
commit bab06c6918

View File

@ -1191,11 +1191,7 @@ 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 self._im = None
# subsequent frames in the image. Image may be
# different size/mode.
Image._decompression_bomb_check(self._tile_size)
self.im = Image.core.new(self.mode, self._tile_size)
def _seek(self, frame: int) -> None: def _seek(self, frame: int) -> None:
self.fp = self._fp self.fp = self._fp
@ -1277,6 +1273,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)