Skip to content

PNG: Should Not Throw Exception when alpha.Length > colorTable.Length in tRNS chunk#3084

Merged
JimBobSquarePants merged 3 commits intomainfrom
bp/fixIssue3082
Mar 12, 2026
Merged

PNG: Should Not Throw Exception when alpha.Length > colorTable.Length in tRNS chunk#3084
JimBobSquarePants merged 3 commits intomainfrom
bp/fixIssue3082

Conversation

@brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR changes AssignColorPalette() and throws a InvalidImageContentException when alpha.Length > colorTable.Length, which is not allowed according to spec. This fixes #3082

if (alpha.Length > colorTable.Length)
{
throw new InvalidImageContentException(
"The tRNS chunk contains more alpha values than there are palette entries.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we perhaps slice the chunk entries to the correct length instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think that's better, I have changed it in c512b14

@JimBobSquarePants JimBobSquarePants changed the title PNG: Throw Exception when alpha.Length > colorTable.Length in tRNS chunk PNG: Should Not Throw Exception when alpha.Length > colorTable.Length in tRNS chunk Mar 12, 2026
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@JimBobSquarePants JimBobSquarePants merged commit fcd8087 into main Mar 12, 2026
12 checks passed
@JimBobSquarePants JimBobSquarePants deleted the bp/fixIssue3082 branch March 12, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexOutOfRangeException in AssignColorPalette when tRNS chunk exceeds PLTE entries

2 participants