aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2019-12-14 19:19:57 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2020-07-02 19:55:08 +0200
commitbbae90e2cb658e336d0104154f37235782253ba9 (patch)
tree07fe9ea178ca17096a72e377c6fec3b5603fc28b /libavcodec
parent41fc3f3851d3a54a14e98b204ccba0f7aaf24967 (diff)
downloadffmpeg-bbae90e2cb658e336d0104154f37235782253ba9.tar.gz
avcodec/pnm: Check that the header is not truncated
Fixes: Ticket8430 Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit c94cb8d9b21baeeecef962c72965dbedc4e0b0e1) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/pnm.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index b06a6e81b5..b5d074f1f8 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -108,6 +108,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)
@@ -188,6 +191,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)