]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/pnm: Check that the header is not truncated
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 14 Dec 2019 18:19:57 +0000 (19:19 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 15 Dec 2019 00:01:22 +0000 (01:01 +0100)
Fixes: Ticket8430
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/pnm.c

index b4e5d3076baa95000873e6a58ffe0138db348397..b5c288194895b77a3d08edcce3006eccab5360a3 100644 (file)
@@ -117,6 +117,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
                 return AVERROR_INVALIDDATA;
             }
         }
+        if (!pnm_space(s->bytestream[-1]))
+            return AVERROR_INVALIDDATA;
+
         /* check that all tags are present */
         if (w <= 0 || h <= 0 || maxval <= 0 || maxval > UINT16_MAX || depth <= 0 || tuple_type[0] == '\0' ||
             av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end)
@@ -197,6 +200,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
         }
     }else
         s->maxval=1;
+
+    if (!pnm_space(s->bytestream[-1]))
+        return AVERROR_INVALIDDATA;
+
     /* more check if YUV420 */
     if (av_pix_fmt_desc_get(avctx->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR) {
         if ((avctx->width & 1) != 0)