Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Tests/test_file_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def test_eoferror() -> None:
# Test that seeking to the last frame does not raise an error
im.seek(n_frames - 1)

# Test seeking past the last frame without calling n_frames first
with Image.open(test_file) as im:
with pytest.raises(EOFError):
im.seek(3)


def test_seek_tell() -> None:
with Image.open(test_file) as im:
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/PsdImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def seek(self, layer: int) -> None:
raise self._fp.ex

# seek to given layer (1..max)
if layer > len(self.layers):
msg = "no more images in PSD file"
raise EOFError(msg)
_, mode, _, tile = self.layers[layer - 1]
self._mode = mode
self.tile = tile
Expand Down
Loading