avcodec/pngdec: Only allow one IHDR chunk
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 29 Jun 2015 19:08:05 +0000 (21:08 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 29 Jun 2015 19:30:57 +0000 (21:30 +0200)
Multiple IHDR chunks are forbidden in PNG
Fixes inconsistency and out of array accesses

Fixes: asan_heap-oob_4d5c5a_1738_cov_2638287726_c-m2-8f2b481b7fd9bd745e620b7c01a18df2.png

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

index ceda383..f8b398f 100644 (file)
@@ -542,6 +542,11 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_INVALIDDATA;
     }
 
         return AVERROR_INVALIDDATA;
     }
 
+    if (s->state & PNG_IHDR) {
+        av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     s->width  = bytestream2_get_be32(&s->gb);
     s->height = bytestream2_get_be32(&s->gb);
     if (av_image_check_size(s->width, s->height, 0, avctx)) {
     s->width  = bytestream2_get_be32(&s->gb);
     s->height = bytestream2_get_be32(&s->gb);
     if (av_image_check_size(s->width, s->height, 0, avctx)) {