Skip to content

reject out-of-range palette register in iff multipalette color map - #1327

Open
arib06 wants to merge 2 commits into
haraldk:masterfrom
arib06:iff-multipalette-register-bounds
Open

reject out-of-range palette register in iff multipalette color map#1327
arib06 wants to merge 2 commits into
haraldk:masterfrom
arib06:iff-multipalette-register-bounds

Conversation

@arib06

@arib06 arib06 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What is fixed No open issue; hardening the IFF multipalette reader against a crafted PCHG chunk.

Why is this change proposed MutableIndexColorModel.adjustColorMap validates palette change registers only against the upper bound (index >= rgbs.length) before writing rgbs[index], so a negative register slips through and writes out of bounds. ILBM PCHG BigLineChanges read a 32-bit register straight from the stream with a signed toShort, so a register like 0xfffe becomes -2 and reaches adjustColorMap through getColorModel/colorMapForRow while rendering, throwing ArrayIndexOutOfBoundsException out of ImageIO.read on a crafted IFF.

What is changed

  • Reject registers below zero as well as above rgbs.length at the existing validation point, matching the current warn-and-ignore behaviour for out-of-range registers.
  • Keep the MP_REG_IGNORE sentinel silently skipped so valid multipalette decoding is unchanged.
  • Added PCHGChunkTest covering a negative register (ignored) and an in-range register (applied).

haraldk
haraldk previously approved these changes Aug 28, 2026

@haraldk haraldk left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! Appreciate your fixes!

In this case it does fix the very specific issue of negative indexes. 👍🏻

However, I think it would provide a lot more value if we could also fix the issue as in the comment:

// TODO: Move validation to chunk (when reading)

Would you like to look into that as well?

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants