Skip to content
Merged
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
7 changes: 4 additions & 3 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,13 @@ def test_non_integer_token(tmp_path: Path) -> None:
pass


def test_header_token_too_long(tmp_path: Path) -> None:
@pytest.mark.parametrize("data", (b"P3\x0cAAAAAAAAAA\xee", b"P6\n 01234567890"))
def test_header_token_too_long(tmp_path: Path, data: bytes) -> None:
path = tmp_path / "temp.ppm"
with open(path, "wb") as f:
f.write(b"P6\n 01234567890")
f.write(data)

with pytest.raises(ValueError, match="Token too long in file header: 01234567890"):
with pytest.raises(ValueError, match="Token too long in file header: "):
with Image.open(path):
pass

Expand Down
4 changes: 2 additions & 2 deletions src/PIL/PpmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def _read_token(self) -> bytes:
msg = "Reached EOF while reading header"
raise ValueError(msg)
elif len(token) > 10:
msg = f"Token too long in file header: {token.decode()}"
raise ValueError(msg)
msg_too_long = b"Token too long in file header: %s" % token
raise ValueError(msg_too_long)
return token

def _open(self) -> None:
Expand Down
Loading