Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
jpc_t2dec: fix various memory leaks in jpc_dec_decodepkt()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jun 28, 2020
1 parent 03db7c8 commit aa8516b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libjasper/jpc/jpc_t2dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
}

if ((present = jpc_bitstream_getbit(inb)) < 0) {
jpc_bitstream_close(inb);
return 1;
}
JAS_DBGLOG(10, ("\n", present));
Expand Down Expand Up @@ -252,10 +253,12 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
if (!cblk->numpasses) {
leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1);
if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) {
jpc_bitstream_close(inb);
return -1;
}
} else {
if ((included = jpc_bitstream_getbit(inb)) < 0) {
jpc_bitstream_close(inb);
return -1;
}
}
Expand All @@ -269,6 +272,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1);
for (;;) {
if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) {
jpc_bitstream_close(inb);
return -1;
}
if (ret) {
Expand All @@ -280,6 +284,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
cblk->firstpassno = cblk->numimsbs * 3;
}
if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) {
jpc_bitstream_close(inb);
return -1;
}
JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
Expand All @@ -288,6 +293,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
mycounter = 0;
if (numnewpasses > 0) {
if ((m = jpc_getcommacode(inb)) < 0) {
jpc_bitstream_close(inb);
return -1;
}
cblk->numlenbits += m;
Expand All @@ -298,6 +304,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
maxpasses = JPC_SEGPASSCNT(passno, cblk->firstpassno, 10000, (ccp->cblkctx & JPC_COX_LAZY) != 0, (ccp->cblkctx & JPC_COX_TERMALL) != 0);
if (!discard && !seg) {
if (!(seg = jpc_seg_alloc())) {
jpc_bitstream_close(inb);
return -1;
}
jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg);
Expand All @@ -312,6 +319,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
mycounter += n;
numnewpasses -= n;
if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
jpc_bitstream_close(inb);
return -1;
}
JAS_DBGLOG(10, ("len=%d ", len));
Expand All @@ -333,6 +341,7 @@ hdroffstart = jas_stream_getrwcount(pkthdrstream);
} else {
if (jpc_bitstream_inalign(inb, 0x7f, 0)) {
jas_eprintf("alignment failed\n");
jpc_bitstream_close(inb);
return -1;
}
}
Expand Down

0 comments on commit aa8516b

Please sign in to comment.