Fix progressive grayscale decode with separate component scans - #124
Open
lpla wants to merge 1 commit into
Open
Conversation
6 tasks
lpla
marked this pull request as ready for review
August 8, 2026 10:53
lpla
force-pushed
the
agent/fix-progressive-grayscale-scans
branch
from
August 8, 2026 11:17
4be2c05 to
d62096b
Compare
Owner
|
Thank you for submitting this PR. Can you please send me the progressive JPEG used for testing so that I can verify the fix? |
Author
|
Here is a synthetic 96×64 reproducer with no third-party content: progressive-separated-component-scans.jpg (SHA-256 Its scans are: Y DC; Cb+Cr DC; Y AC; Cb AC; Cr AC. With |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Progressive JPEGs may place the luminance DC coefficients in the first scan and defer both chroma components to a later scan. When decoding that first scan as
EIGHT_BIT_GRAYSCALE,DecodeJPEG()currently callsJPEGDecodeMCU_P(..., MCU_SKIP, ...)for Cb and Cr even though neither component is present in the entropy stream.Check each scan component's existing
component_neededflag before consuming its entropy data. This avoids reading absent chroma data and lets the valid luminance-only scan produce the documented 1/8-scale progressive preview.This adds no allocation and leaves baseline, single-component progressive, and color-output paths unchanged.
Reproduction
The failure can be reproduced without third-party image content by creating a 4:4:4 progressive JPEG with this libjpeg scan script:
Decode it using:
At current
master(8628297), the decoder attempts the absent chroma blocks and crashes under the host harness. With this patch it returns success and invokes the draw callback for all eight output rows.Validation
decode=1 error=0 draw_calls=8.decode=1 error=0 draw_calls=113.decode=1 error=0 draw_calls=8.decode=1 error=0 draw_calls=8.Emulator evidence
These screenshots are emulator-only evidence, not physical-device validation.
Related, but distinct because it concerns components that are present in the scan: #119.