Skip to content

Do not raise error from unknown channel id when parsing PSD layers#9644

Open
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:psd_channel
Open

Do not raise error from unknown channel id when parsing PSD layers#9644
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:psd_channel

Conversation

@radarhere
Copy link
Copy Markdown
Member

@radarhere radarhere commented Jun 1, 2026

Within a PSD layer, it is possible that an unsupported channel ID will trigger an IndexError.

for _ in range(ct_types):
type = i16(read(2))
if type == 65535:
b = "A"
else:
b = "RGBA"[type]
bands.append(b)

However, Pillow has already established that if the combination of channels don't lead to a recognised mode, that's not cause for an error.

# figure out the image mode
bands.sort()
if bands == ["R"]:
mode = "L"
elif bands == ["B", "G", "R"]:
mode = "RGB"
elif bands == ["A", "B", "G", "R"]:
mode = "RGBA"
else:
mode = "" # unknown

This PR applies that same logic to the first step, since conceptually, not knowing what type of data is in a band is a subset of not knowing what mode the overall layer is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant