Skip to content

Commit 818500b

Browse files
committed
Raise an error if map depth is unknown
1 parent 63987b7 commit 818500b

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Tests/images/p_8.tga

18 Bytes
Binary file not shown.

Tests/test_file_tga.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from PIL import Image
10+
from PIL import Image, UnidentifiedImageError
1111

1212
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
1313

@@ -65,6 +65,11 @@ def roundtrip(original_im) -> None:
6565
roundtrip(original_im)
6666

6767

68+
def test_palette_depth_8(tmp_path: Path) -> None:
69+
with pytest.raises(UnidentifiedImageError):
70+
Image.open("Tests/images/p_8.tga")
71+
72+
6873
def test_palette_depth_16(tmp_path: Path) -> None:
6974
with Image.open("Tests/images/p_16.tga") as im:
7075
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/p_16.png")

src/PIL/TgaImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def _open(self) -> None:
128128
self.palette = ImagePalette.raw(
129129
"BGRA", b"\0" * 4 * start + self.fp.read(4 * size)
130130
)
131+
else:
132+
msg = "unknown TGA map depth"
133+
raise SyntaxError(msg)
131134

132135
# setup tile descriptor
133136
try:

0 commit comments

Comments
 (0)