Skip to content

Conversation

@radarhere
Copy link
Member

Three formats - APNG, FLI and GIF raise an error if _seek is called to seek to frame that isn't the next one or the first one.

def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
if frame < self.__frame:
self._seek(0)
for f in range(self.__frame + 1, frame + 1):
self._seek(f)
def _seek(self, frame: int) -> None:
if frame == 0:
self.__frame = -1
self._fp.seek(self.__rewind)
self.__offset = 128
else:
# ensure that the previous frame was loaded
self.load()
if frame != self.__frame + 1:
msg = f"cannot seek to frame {frame}"
raise ValueError(msg)

_seek shouldn't be called by end users, but ensuring it is called in the correct way internally would guard against bugs.

@hugovk hugovk merged commit e946c7b into python-pillow:main Mar 6, 2025
53 of 54 checks passed
@radarhere radarhere deleted the seek branch March 6, 2025 20:46
eyedav pushed a commit to eyedav/Pillow that referenced this pull request Jul 19, 2025
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants