Skip to content

Prevent opening P TGA images without a palette #7797

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 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Set mode to L if palette is missing
  • Loading branch information
radarhere committed Feb 13, 2024
commit 63987b7abaf6907a8985b867be154debfef0ec1b
5 changes: 5 additions & 0 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def test_small_palette(tmp_path: Path) -> None:
assert reloaded.getpalette() == colors


def test_missing_palette() -> None:
with Image.open("Tests/images/dilation4.lut") as im:
assert im.mode == "L"


def test_save_wrong_mode(tmp_path: Path) -> None:
im = hopper("PA")
out = str(tmp_path / "temp.tga")
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _open(self) -> None:
elif depth == 16:
self._mode = "LA"
elif imagetype in (1, 9):
self._mode = "P"
self._mode = "P" if colormaptype else "L"
elif imagetype in (2, 10):
self._mode = "RGB"
if depth == 32:
Expand Down