avcodec/jpeg2000dec: check len before parsing header
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 14 Jun 2013 17:20:10 +0000 (19:20 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 14 Jun 2013 17:34:00 +0000 (19:34 +0200)
Fixes out of array read

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/jpeg2000dec.c

index 11fa7f6..f821292 100644 (file)
@@ -1249,9 +1249,9 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
         if (marker == JPEG2000_EOC)
             break;
 
-        if (bytestream2_get_bytes_left(&s->g) < 2)
+        len = bytestream2_get_be16(&s->g);
+        if (len < 2 || bytestream2_get_bytes_left(&s->g) < len - 2)
             return AVERROR(EINVAL);
-        len = bytestream2_get_be16u(&s->g);
         switch (marker) {
         case JPEG2000_SIZ:
             ret = get_siz(s);