avcodec/jpeg2000dec: More completely check cdef

Fixes out of array access
Fixes: j2k-poc.bin

Found-by: Lucas Leong <wmliang.tw@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 0aada30510)

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2016-01-27 17:13:10 +01:00
parent 9a1433683c
commit a944744f19
1 changed files with 9 additions and 5 deletions

View File

@ -1292,11 +1292,15 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
if (tile->codsty[0].mct) if (tile->codsty[0].mct)
mct_decode(s, tile); mct_decode(s, tile);
if (s->cdef[0] < 0) { for (x = 0; x < s->ncomponents; x++) {
for (x = 0; x < s->ncomponents; x++) if (s->cdef[x] < 0) {
s->cdef[x] = x + 1; for (x = 0; x < s->ncomponents; x++) {
if ((s->ncomponents & 1) == 0) s->cdef[x] = x + 1;
s->cdef[s->ncomponents-1] = 0; }
if ((s->ncomponents & 1) == 0)
s->cdef[s->ncomponents-1] = 0;
break;
}
} }
if (s->precision <= 8) { if (s->precision <= 8) {