Skip to content

Conversation

@radarhere
Copy link
Member

If you open a PSD file, use n_frames, and then seek too far, an EOFError is raised as expected.

>>> from PIL import Image
>>> im = Image.open("Tests/images/hopper.psd")
>>> im.n_frames
2
>>> im.seek(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/PsdImagePlugin.py", line 172, in seek
    if not self._seek_check(layer):
  File "PIL/ImageFile.py", line 460, in _seek_check
    raise EOFError(msg)
EOFError: attempt to seek outside sequence

As the trace says, this is raised by _seek_check(), because _n_frames has been populated.

However, if you do not use n_frames, an IndexError is raised instead.

>>> im = Image.open("Tests/images/hopper.psd")
>>> im.seek(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/PsdImagePlugin.py", line 178, in seek
    _, mode, _, tile = self.layers[layer - 1]
IndexError: list index out of range

This is because PsdImagePlugin itself does not have any explicit handling for when you seek too far. This PR adds it, changing the second scenario to also raise an EOFError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant