diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index 68bb7a41ec..b99b26a390 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -63,6 +63,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, if (avctx->skip_frame >= AVDISCARD_ALL) return avpkt->size; + if (avctx->width * avctx->height / 8 > s->bytestream_end - s->bytestream) + return AVERROR_INVALIDDATA; + if ((ret = ff_get_buffer(avctx, p, 0)) < 0) return ret; avctx->bits_per_raw_sample = av_log2(s->maxval) + 1;