Skip to content

check reconstructed component sizes before writing ppm/pfm/tif - #426

Open
naaz234 wants to merge 1 commit into
aous72:masterfrom
naaz234:expand-recon-size-check
Open

naaz234 wants to merge 1 commit into
aous72:masterfrom
naaz234:expand-recon-size-check

Conversation

@naaz234

@naaz234 naaz234 commented Nov 15, 2026

Copy link
Copy Markdown

ojph_expand only compares XRsiz/YRsiz across components before writing .ppm, .pfm or .tif, then sizes the writer from component 0's reconstructed width and height. With -skip_res, a COC that points some components at a vertical-only DFS changes their reconstructed size without touching XRsiz/YRsiz, so ppm_out::write (and the pfm/tif writers) read component 0's width of samples from the shorter line buffers of the other components, and the stale bytes end up in the output file. ASan does not flag it because the lines sit inside the codestream's pooled allocation. With a horizontal-only DFS the heights differ instead, and the interleaved pull loop in ojph_expand never terminates.

Repro: a 4096x32, 3-component reversible stream with a DFS segment (every level vertical-only) and COC segments selecting it for components 0 and 1, decoded with ojph_expand -i dfs.j2c -o out.ppm -skip_res 5,5, writes a 4096x1 PPM whose third channel holds 128 decoded samples followed by 3968 values read past component 2's 128-sample line. With the patch it stops with the existing "same downsampling ratio" error, normal files (with and without -skip_res) decode as before, and the 138 tests pass.

This branch has not been deployed

No deployments
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