avcodec/ffv1enc: Allocate smaller packet if the worst case size cannot be allocated
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 8 Dec 2016 22:51:45 +0000 (23:51 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 10 Dec 2016 23:21:53 +0000 (00:21 +0100)
We are checking during encoding if there is enough space as version 4 needs that
check.

Fixes Ticket6005

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 38a7834bbb24ef62466b076715e0add60e1d6962)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/ffv1enc.c

index efa0ff7..158cbab 100644 (file)
@@ -1144,6 +1144,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     if (f->version > 3)
         maxsize = AV_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;
 
+    if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {
+        av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n");
+        maxsize = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32;
+    }
+
     if ((ret = ff_alloc_packet2(avctx, pkt, maxsize, 0)) < 0)
         return ret;