From abf7e59e2b9bfc7a6493e517356359d70d8a03d7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 25 Oct 2026 07:03:26 +1100 Subject: [PATCH] Do not load previous frame --- src/PIL/ImageFile.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 751bfefe5b0..6ab63602f5a 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -310,13 +310,15 @@ def verify(self) -> None: def load(self) -> Image.core.PixelAccess | None: """Load image data based on tile list""" - if not self.tile and self._im is None: - msg = "cannot load this image" - raise OSError(msg) - - pixel = Image.Image.load(self) if not self.tile: - return pixel + if self._im is None: + msg = "cannot load this image" + raise OSError(msg) + return Image.Image.load(self) + + if self._im is not None: + # If this image has been closed, raise an error + self.im self.map: mmap.mmap | None = None use_mmap = self.filename and len(self.tile) == 1