diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 48279f2928..2192ea5874 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -304,7 +304,10 @@ static int buf_realloc(struct ogg_stream *os, int size) { /* Even if invalid guarantee there's enough memory to read the page */ if (os->bufsize - os->bufpos < size) { - uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE); + uint8_t *nb; + if (os->bufsize > (UINT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) / 2) + return AVERROR(ENOMEM); + nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE); if (!nb) return AVERROR(ENOMEM); os->buf = nb;