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>
This commit is contained in:
Michael Niedermayer 2013-07-01 10:01:08 +02:00 committed by Luca Barbato
parent eae63e3c15
commit fd54dd028b
1 changed files with 3 additions and 2 deletions

View File

@ -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);