10000 Do not decode bytes in PPM error message by radarhere · Pull Request #8958 · python-pillow/Pillow · GitHub
[go: up one dir, main page]

Skip to content

Do not decode bytes in PPM error message #8958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
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
0