Raise an error if map depth is unknown

This commit is contained in:
Andrew Murray 2024-02-14 07:10:44 +11:00
parent 63987b7aba
commit 818500b329
3 changed files with 9 additions and 1 deletions

BIN
Tests/images/p_8.tga Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@ from pathlib import Path
import pytest
from PIL import Image
from PIL import Image, UnidentifiedImageError
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
@ -65,6 +65,11 @@ def test_sanity(mode, tmp_path: Path) -> None:
roundtrip(original_im)
def test_palette_depth_8(tmp_path: Path) -> None:
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/p_8.tga")
def test_palette_depth_16(tmp_path: Path) -> None:
with Image.open("Tests/images/p_16.tga") as im:
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/p_16.png")

View File

@ -128,6 +128,9 @@ class TgaImageFile(ImageFile.ImageFile):
self.palette = ImagePalette.raw(
"BGRA", b"\0" * 4 * start + self.fp.read(4 * size)
)
else:
msg = "unknown TGA map depth"
raise SyntaxError(msg)
# setup tile descriptor
try: