Skip to content

Commit 79185d3

Browse files
committed
Fixes #401.
JPEG-2000 (JPC) Encoder: - Added some missing range checking on several coding parameters (e.g., precint width/height and codeblock width/height).
1 parent 1fd1fb4 commit 79185d3

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

data/test/other/poc_401.pnm

182 Bytes
Binary file not shown.

src/libjasper/jpc/jpc_enc.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,18 +484,36 @@ static jpc_enc_cp_t *cp_create(const char *optstr, jas_image_t *image)
484484
cp->tileheight = atoi(jas_tvparser_getval(tvp));
485485
break;
486486
case OPT_PRCWIDTH:
487-
prcwidthexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
487+
i = atoi(jas_tvparser_getval(tvp));
488+
if (i <= 0) {
489+
jas_logerrorf("invalid precinct width (%d)\n", i);
490+
goto error;
491+
}
492+
prcwidthexpn = jpc_floorlog2(i);
488493
break;
489494
case OPT_PRCHEIGHT:
490-
prcheightexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
495+
i = atoi(jas_tvparser_getval(tvp));
496+
if (i <= 0) {
497+
jas_logerrorf("invalid precinct height (%d)\n", i);
498+
goto error;
499+
}
500+
prcheightexpn = jpc_floorlog2(i);
491501
break;
492502
case OPT_CBLKWIDTH:
493-
tccp->cblkwidthexpn =
494-
jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
503+
i = atoi(jas_tvparser_getval(tvp));
504+
if (i <= 0) {
505+
jas_logerrorf("invalid code block width (%d)\n", i);
506+
goto error;
507+
}
508+
tccp->cblkwidthexpn = jpc_floorlog2(i);
495509
break;
496510
case OPT_CBLKHEIGHT:
497-
tccp->cblkheightexpn =
498-
jpc_floorlog2(atoi(jas_tvparser_getval(tvp)));
511+
i = atoi(jas_tvparser_getval(tvp));
512+
if (i <= 0) {
513+
jas_logerrorf("invalid code block height (%d)\n", i);
514+
goto error;
515+
}
516+
tccp->cblkheightexpn = jpc_floorlog2(i);
499517
break;
500518
case OPT_MODE:
501519
if ((tagid = jas_taginfo_nonull(jas_taginfos_lookup(modetab,

src/libjasper/jpc/jpc_t2dec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_str
348348
const unsigned n = JAS_MIN((unsigned)numnewpasses, maxpasses);
349349
mycounter += n;
350350
numnewpasses -= n;
351-
if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
351+
if ((len = jpc_bitstream_getbits(inb,
352+
cblk->numlenbits + jpc_floorlog2(n))) < 0) {
352353
jpc_bitstream_close(inb);
353354
jas_logerrorf("cannot get bits\n");
354355
return -1;

0 commit comments

Comments
 (0)