@param cblksty
@param first
*/
-static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
+static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
/**
Decode a packet of a tile from a source buffer
@param t2 T2 handle
return (c - dest);
}
-static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
+static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
opj_tcd_seg_t* seg;
- cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
+ opj_tcd_seg_t* segs;
+ segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
+
+ if (segs == NULL)
+ {
+ return OPJ_FALSE;
+ }
+ cblk->segs = segs;
+
seg = &cblk->segs[index];
seg->data = NULL;
seg->dataindex = 0;
} else {
seg->maxpasses = 109;
}
+
+ return OPJ_TRUE;
}
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
cblk->numlenbits += increment;
segno = 0;
if (!cblk->numsegs) {
- t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1);
+ if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1))
+ {
+ opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
+ bio_destroy(bio);
+ return -999;
+ }
} else {
segno = cblk->numsegs - 1;
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
++segno;
- t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
+ if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0))
+ {
+ opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
+ bio_destroy(bio);
+ return -999;
+ }
}
}
n = cblk->numnewpasses;
n -= cblk->segs[segno].numnewpasses;
if (n > 0) {
++segno;
- t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
+ if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0))
+ {
+ opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
+ bio_destroy(bio);
+ return -999;
+ }
}
} while (n > 0);
}
} else {
e = 0;
}
- if(e == -999) return -999;
+ if(e == -999)
+ {
+ pi_destroy(pi, cp, tileno);
+ return -999;
+ }
/* progression in resolution */
image->comps[pi[pino].compno].resno_decoded =
(e > 0) ?