Commit b5587fd2 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/jpeg2000: Only allocate Jpeg2000Pass for the encoder

Reduces memory needed.
Fixes: OOM
Fixes: 4427/clusterfuzz-testcase-minimized-5106919271301120

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpegSigned-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 06740870
...@@ -941,7 +941,9 @@ static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno ...@@ -941,7 +941,9 @@ static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno
} }
if (!prec->cblk[cblkno].data) if (!prec->cblk[cblkno].data)
prec->cblk[cblkno].data = av_malloc(1 + 8192); prec->cblk[cblkno].data = av_malloc(1 + 8192);
if (!prec->cblk[cblkno].data) if (!prec->cblk[cblkno].passes)
prec->cblk[cblkno].passes = av_malloc_array(JPEG2000_MAX_PASSES, sizeof (*prec->cblk[cblkno].passes));
if (!prec->cblk[cblkno].data || !prec->cblk[cblkno].passes)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
encode_cblk(s, &t1, prec->cblk + cblkno, tile, xx1 - xx0, yy1 - yy0, encode_cblk(s, &t1, prec->cblk + cblkno, tile, xx1 - xx0, yy1 - yy0,
bandpos, codsty->nreslevels - reslevelno - 1); bandpos, codsty->nreslevels - reslevelno - 1);
......
...@@ -606,6 +606,7 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) ...@@ -606,6 +606,7 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
for (cblkno = 0; cblkno < nb_code_blocks; cblkno ++) { for (cblkno = 0; cblkno < nb_code_blocks; cblkno ++) {
Jpeg2000Cblk *cblk = &prec->cblk[cblkno]; Jpeg2000Cblk *cblk = &prec->cblk[cblkno];
av_freep(&cblk->data); av_freep(&cblk->data);
av_freep(&cblk->passes);
} }
av_freep(&prec->cblk); av_freep(&prec->cblk);
} }
......
...@@ -173,7 +173,7 @@ typedef struct Jpeg2000Cblk { ...@@ -173,7 +173,7 @@ typedef struct Jpeg2000Cblk {
int nb_terminations; int nb_terminations;
int nb_terminationsinc; int nb_terminationsinc;
int data_start[JPEG2000_MAX_PASSES]; int data_start[JPEG2000_MAX_PASSES];
Jpeg2000Pass passes[JPEG2000_MAX_PASSES]; Jpeg2000Pass *passes;
int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
} Jpeg2000Cblk; // code block } Jpeg2000Cblk; // code block
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment