Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions Tests/test_file_psd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
import sys
import warnings

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/PIL/PsdImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading