refactor: Extract maximum transformed pixel depth calculation - #912
Open
17krishna8 wants to merge 3 commits into
Open
refactor: Extract maximum transformed pixel depth calculation#91217krishna8 wants to merge 3 commits into
17krishna8 wants to merge 3 commits into
Conversation
The CDfcTL entry declared max_length=25 with min_length=26, which no chunk length can satisfy: png_handle_chunk rejects length < 26 as "too short" and everything else as "too long". An fcTL chunk is exactly 26 bytes (4-byte sequence number + 22 bytes of frame data), so both bounds must be 26, matching the CDacTL pattern where an acTL is exactly 8 bytes. The entry is currently unreachable because the APNG handlers are #defined to NULL and such chunks are routed to unknown-chunk handling, but the table must stay correct so that enabling native table-driven APNG dispatch does not silently reject every valid fcTL.
When png_handle_fcTL declined an fcTL chunk (for example an oversized frame description for the leading frame), the progressive reader reported "Missing required fcTL chunk in APNG stream" even though the fcTL was present in the stream; the misleading message sent users hunting for a nonexistent missing-chunk problem. The sequential reader already aborts such streams with the accurate "Out-of-order sequence number"/"Oversized frame in fcTL" diagnostics produced by the handler itself, so only the follow-up message here needs to describe the actual situation: the chunk was seen but not accepted.
png_read_start_row() open-codes the computation of the maximum pixel depth that a row can have after all enabled read transformations. The accompanying warning notes that png_read_transform_info (pngrtran.c) performs similar calculations and that the two must agree, otherwise memory overwrites become possible; the TODO asks for this to be fixed. As a first step, move the computation into its own function, png_read_max_pixel_depth(), so that: - the logic exists in exactly one place within pngrutil.c, - the invariant it maintains is documented next to the code, - follow-up work can share or assert on this value instead of re-deriving it. No functional change; behavior is identical for all configurations.
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.
Consolidates the maximum-transformed-pixel-depth computation flagged by the existing WARNING/TODO in png_read_start_row (pngrutil.c): the same value must agree with png_read_transform_info (pngrtran.c) and png_do_read_transformations, or memory overwrites become possible. This moves the pngrutil.c instance into a single documented static helper, png_read_max_pixel_depth(), as the first step of making that invariant enforceable instead of folklore.
No functional change. Validated: ASan+UBSan build, full CTest suite 37/37, pngtest, plus a 20-run APNG stress corpus (sequential + progressive APIs). Follow-up to #911.