jpeg2000: check len before parsing header

Avoid overread.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
pull/26/merge
Michael Niedermayer 12 years ago committed by Luca Barbato
parent eae63e3c15
commit fd54dd028b
  1. 5
      libavcodec/jpeg2000dec.c

@ -1241,9 +1241,10 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
if (marker == JPEG2000_EOC) if (marker == JPEG2000_EOC)
break; break;
if (bytestream2_get_bytes_left(&s->g) < 2)
return AVERROR_INVALIDDATA;
len = bytestream2_get_be16u(&s->g); len = bytestream2_get_be16u(&s->g);
if (len < 2 || bytestream2_get_bytes_left(&s->g) < len - 2)
return AVERROR_INVALIDDATA;
switch (marker) { switch (marker) {
case JPEG2000_SIZ: case JPEG2000_SIZ:
ret = get_siz(s); ret = get_siz(s);

Loading…
Cancel
Save