diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 538b1406b36..79cc8bc00a0 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -1,5 +1,6 @@ from __future__ import annotations +import io import sys import warnings @@ -157,6 +158,21 @@ def test_no_icc_profile() -> None: assert "icc_profile" not in im.info +def test_unknown_channel_id() -> None: + with open("Tests/images/rgba.psd", "rb") as fp: + data = fp.read() + + # Set channel id to 4 + data = data[:90] + b"\x00\x04" + data[92:] + + b = io.BytesIO(data) + with Image.open(b) as im: + assert isinstance(im, PsdImagePlugin.PsdImageFile) + + # unknown mode + assert im.layers[0][1] == "" + + def test_combined_larger_than_size() -> None: # The combined size of the individual parts is larger than the # declared 'size' of the extra data field, resulting in a backwards seek. diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index dd3d5ab95fd..201909abde6 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -222,12 +222,14 @@ def read(size: int) -> bytes: continue for _ in range(ct_types): - type = i16(read(2)) + channel_id = i16(read(2)) - if type == 65535: + if channel_id == 65535: b = "A" + elif channel_id < 4: + b = "RGBA"[channel_id] else: - b = "RGBA"[type] + b = "" bands.append(b) read(4) # size