X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fjpeg2000.c;h=8e90980976e52772bd215e518a3baf58c615cd3f;hb=9a15af48284b951701b7e6b9dcc81b4212c6ca95;hp=afeb9df27c40849fa7ef9282d4ebc437a6998590;hpb=a629bc99fd111f9275c1e3b54dc358efeeae18d9;p=ffmpeg diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index afeb9df27c4..8e90980976e 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -357,10 +357,8 @@ static int init_prec(Jpeg2000Band *band, comp->reslevel[reslevelno-1].coord[1][0]; } - cblk->zero = 0; cblk->lblock = 3; cblk->length = 0; - memset(cblk->lengthinc, 0, sizeof(cblk->lengthinc)); cblk->npasses = 0; } @@ -543,6 +541,9 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, if (!reslevel->band) return AVERROR(ENOMEM); + if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y * reslevel->nbands > avctx->max_pixels / sizeof(*reslevel->band->prec)) + return AVERROR(ENOMEM); + for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++) { ret = init_band(avctx, reslevel, comp, codsty, qntsty, @@ -598,9 +599,21 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) { if (band->prec) { Jpeg2000Prec *prec = band->prec + precno; + int nb_code_blocks = prec->nb_codeblocks_height * prec->nb_codeblocks_width; + av_freep(&prec->zerobits); av_freep(&prec->cblkincl); - av_freep(&prec->cblk); + if (prec->cblk) { + int cblkno; + for (cblkno = 0; cblkno < nb_code_blocks; cblkno ++) { + Jpeg2000Cblk *cblk = &prec->cblk[cblkno]; + av_freep(&cblk->data); + av_freep(&cblk->passes); + av_freep(&cblk->lengthinc); + av_freep(&cblk->data_start); + } + av_freep(&prec->cblk); + } } }