Skip to content

fix(jpeg2000): don't overread sYCC conversion with < 3 channels - #5634

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-j2k-sycc
Open

lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-j2k-sycc

Conversation

@lgritz

@lgritz lgritz commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

The reader unconditionally applied the yuv_to_rgb conversion to all OPJ_CLRSPC_SYCC tagged images. The conversion assumes three samples per pixel, so a 1-channel image tagged sYCC read and wrote two samples past the end of every scanline buffer.

Solution: Only do the yuv_to_rgb conversion if channels >= 3. A lone channel is decoded as plain luma. This matches the behavior of OpenJPEG's own reference decoder.

It's a one-line code fix, and all the rest of the changes in this patch are tests and documenting what went wrong.

Found by Anthropic using Claude and manually validated by Ada Logics.

Assisted-by: Claude Code / claude-opus-5-5

The reader unconditionally applied the yuv_to_rgb conversion to all
OPJ_CLRSPC_SYCC tagged images. The conversion assumes three samples
per pixel, so a 1-channel image tagged sYCC read and wrote two samples
past the end of every scanline buffer.

Solution: Only do the yuv_to_rgb conversion if channels >= 3.  A lone
channel is decoded as plain luma. This matches the behavior of
OpenJPEG's own reference decoder.

It's a one-line code fix, and all the rest of the changes in this
patch are tests and documenting what went wrong.

Assisted-by: Claude Code / claude-opus-5-5

Signed-off-by: Larry Gritz <lg@larrygritz.com>
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