Skip to content

Reject precinct exponents below 1 in the JPC encoder - #431

Open
iliasabk wants to merge 1 commit into
jasper-software:masterfrom
iliasabk:fix/enc-precinct-expn
Open

iliasabk wants to merge 1 commit into
jasper-software:masterfrom
iliasabk:fix/enc-precinct-expn

Conversation

@iliasabk

Copy link
Copy Markdown

Summary

Fixes #422 — prcwidth=1 (and prcheight=1) passes the encoder's positive-value option check, but jpc_floorlog2(1) = 0, so prcwidthexpn = 0. For every resolution level above 0 the encoder then computes cbgwidthexpn = prcwidthexpn - 1 = -1, the negative exponent drives the code-block-group geometry to produce zero code blocks, and jpc_tagtree_create(0, ...) aborts on assert(numleafsh > 0 && numleafsv > 0) (SIGABRT; a negative shift exponent under UBSan).

Fix

The decoder already rejects prcwidthexpn < 1 for every resolution level (jpc_dec.c:837). This adds the mirror bound in cp_create(), right where the existing > 15 checks live, so the invalid option is rejected at option-parse time with a proper error message.

Testing

  • Before: jasper --input in.pgm --output out.jpc --output-format jpc -O prcwidth=1 → runtime error: shift exponent 4294967295 is too large (UBSan) / assertion abort (release)
  • After: invalid precinct width → jpc_encode failed (graceful)
  • prcwidth=4 and default encoding still work normally

prcwidth=1 (and likewise prcheight=1) yields prc widthexpn=0 via
jpc_floorlog2, which is accepted by the positive-value option check.
For resolution levels above 0 the encoder then computes
cbgwidthexpn = prcwidthexpn - 1 = -1, and the negative exponent makes
the precinct/code-block geometry produce zero code blocks, ending in
a reachable assertion in jpc_tagtree_create() (SIGABRT) or a negative
shift exponent (UB).

The decoder already rejects prcwidthexpn < 1 (jpc_dec.c); mirror that
bound in cp_create() where the > 15 check already lives, so invalid
options are rejected at option-parse time.

Fixes jasper-software#422.

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.

[Security Issue] JasPer JPEG-2000 encoder reachable assertion for prcwidth=1

1 participant