avcodec/jpeg2000dec: Check precno before using it in JPEG2000_PGOD_CPRL

Fixes out of array reads
Fixes: asan_heap-oob_f0de57_6823_mjp2.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/49/head
Michael Niedermayer 11 years ago
parent 638d79a9d0
commit 3d5a5e86be
  1. 4
      libavcodec/jpeg2000dec.c

@ -889,6 +889,10 @@ static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
prcx = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width; prcx = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;
prcy = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height; prcy = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;
precno = prcx + rlevel->num_precincts_x * prcy; precno = prcx + rlevel->num_precincts_x * prcy;
if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y)
return AVERROR_PATCHWELCOME;
for (layno = 0; layno < tile->codsty[0].nlayers; layno++) { for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
if ((ret = jpeg2000_decode_packet(s, codsty, rlevel, if ((ret = jpeg2000_decode_packet(s, codsty, rlevel,
precno, layno, precno, layno,

Loading…
Cancel
Save