This commit is contained in:
Andrew Murray 2025-05-23 16:17:52 +00:00 committed by GitHub
commit b236b03076
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -94,8 +94,8 @@ class PpmImageFile(ImageFile.ImageFile):
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: