mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Merge pull request #7882 from radarhere/ppm
This commit is contained in:
commit
ca973709a0
|
@ -241,13 +241,23 @@ def test_plain_ppm_token_too_long(tmp_path: Path, data: bytes) -> None:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
def test_plain_ppm_value_negative(tmp_path: Path) -> None:
|
||||||
|
path = str(tmp_path / "temp.ppm")
|
||||||
|
with open(path, "wb") as f:
|
||||||
|
f.write(b"P3\n128 128\n255\n-1")
|
||||||
|
|
||||||
|
with Image.open(path) as im:
|
||||||
|
with pytest.raises(ValueError, match="Channel value is negative"):
|
||||||
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
def test_plain_ppm_value_too_large(tmp_path: Path) -> None:
|
def test_plain_ppm_value_too_large(tmp_path: Path) -> None:
|
||||||
path = str(tmp_path / "temp.ppm")
|
path = str(tmp_path / "temp.ppm")
|
||||||
with open(path, "wb") as f:
|
with open(path, "wb") as f:
|
||||||
f.write(b"P3\n128 128\n255\n256")
|
f.write(b"P3\n128 128\n255\n256")
|
||||||
|
|
||||||
with Image.open(path) as im:
|
with Image.open(path) as im:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="Channel value too large"):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,9 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
msg = b"Token too long found in data: %s" % token[: max_len + 1]
|
msg = b"Token too long found in data: %s" % token[: max_len + 1]
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
value = int(token)
|
value = int(token)
|
||||||
|
if value < 0:
|
||||||
|
msg_str = f"Channel value is negative: {value}"
|
||||||
|
raise ValueError(msg_str)
|
||||||
if value > maxval:
|
if value > maxval:
|
||||||
msg_str = f"Channel value too large for this mode: {value}"
|
msg_str = f"Channel value too large for this mode: {value}"
|
||||||
raise ValueError(msg_str)
|
raise ValueError(msg_str)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user