opj_j2k: fix invalid tile part index error when decoding tiles with interleaved tile-parts#1644
Merged
Merged
Conversation
…nterleaved tile-parts (uclouvain#1558) When a tile's tile-parts are interleaved across tiles and TNsot is only declared in its last tile-part, opj_j2k_decode_one_tile() could not build a reliable index and seeked to m_last_sot_read_pos, which may point past the tile's first tile-part. Seek to the start of the codestream instead so the tile-parts are read in order, and add a self-contained non-regression test.
Contributor
Author
|
That one failing build action is due to a download hiccup, but it doesn't seem to be something I can retry myself. |
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.
Fixes #1558
Problem
opj_get_decoded_tile()failed with "Invalid tile part index for tile number N. Got X, expected 0" on codestreams whose tile-parts are interleaved across tiles (all tiles' first tile-part, then all tiles' second tile-part, etc.) and that only declare the total tile-part count (TNsot) in each tile's last tile-part.Cause
When the tile is decoded, the prior tile decode stops as soon as its own last tile-part is consumed, which can be reached before the target tile's final tile-part (the one containing
TNsot). The target tile'snb_tpsis never set and its tile-part start positions are never recorded, soopj_j2k_decode_one_tile()takes the "index not built" fallback. That fallback seeks tom_last_sot_read_pos, which for an interleaved layout points past the tile's first tile-part, causing the decoder to encounter a non-zeroTPsotfirst and abort.This only occurs when multiple tiles are decoded from the same codec (e.g.
j2k_random_tile_access). The first tile always succeeds because the index hasn't been built yet.Fix
main_head_end+ 2) instead, so the target tile's tile-parts are read in order. The faster index-based path used by ordered codestreams is unchanged.rta_interleaved_tile_parts): it encodes a small multi-tile image, rewrites it into the interleaved layout, then decodes every tile and checks the samples against a full-image decode. The test fails before this fix and passes after it, with no external test data dependency.