History

avcodec/jpeg2000dec: implement cdef remapping during pixel format matching

Fixes: out of array access Fixes: poc.jp2

Michael Niedermayer committed 1 year ago

Commit 01a292c1 parent 104d6841 file · +11 −1Browse files

Unified · Split

libavcodec/jpeg2000dec.c+11−1
@@ -282,6 +282,14 @@ static int get_siz(Jpeg2000DecoderContext *s) · 281 unmodified lines
282282 }
283283 // after here we no longer have to consider negative cdef
284284
285+ int cdef_used = 0;
286+ for (i = 0; i < s->ncomponents; i++)
287+ cdef_used |= 1<<s->cdef[i];
288+
289+ // Check that the channels we have are what we expect for the number of components
290+ if (cdef_used != ((int[]){0,2,3,14,15})[s->ncomponents])
291+ return AVERROR_INVALIDDATA;
292+
285293 for (i = 0; i < s->ncomponents; i++) { // Ssiz_i XRsiz_i, YRsiz_i
286294 uint8_t x = bytestream2_get_byteu(&s->g);
287295 s->cbps[i] = (x & 0x7f) + 1;
@@ -294,7 +302,9 @@ static int get_siz(Jpeg2000DecoderContext *s) · 6 unmodified lines
294302 av_log(s->avctx, AV_LOG_ERROR, "Invalid sample separation %d/%d\n", s->cdx[i], s->cdy[i]);
295303 return AVERROR_INVALIDDATA;
296304 }
297− log2_chroma_wh |= s->cdy[i] >> 1 << i * 4 | s->cdx[i] >> 1 << i * 4 + 2;
305+ int i_remapped = s->cdef[i] ? s->cdef[i]-1 : (s->ncomponents-1);
306+
307+ log2_chroma_wh |= s->cdy[i] >> 1 << i_remapped * 4 | s->cdx[i] >> 1 << i_remapped * 4 + 2;
298308 }
299309
300310 s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t