]> git.sesse.net Git - ffmpeg/commitdiff
avformat/aviobuf: Stop restricting dynamic buffer sizes to INT_MAX/2
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 24 May 2020 02:04:29 +0000 (04:04 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 11 Jun 2020 01:09:56 +0000 (03:09 +0200)
This has originally been done in 568e18b15e2ddf494fd8926707d34ca08c8edce5
as a precaution against integer overflows, but it is actually easy to
support the full range of int without overflows.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/aviobuf.c

index 12408fd211a5a0de792cdb1485b4845376c8bd9d..85f6f06de03684fdf3560882649c6a9806e058db 100644 (file)
@@ -1288,7 +1288,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
 
     /* reallocate buffer if needed */
     new_size = (unsigned)d->pos + buf_size;
-    if (new_size < d->pos || new_size > INT_MAX/2)
+    if (new_size < d->pos || new_size > INT_MAX)
         return -1;
     if (new_size > d->allocated_size) {
         unsigned new_allocated_size = d->allocated_size ? d->allocated_size
@@ -1297,6 +1297,8 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
         while (new_size > new_allocated_size)
             new_allocated_size += new_allocated_size / 2 + 1;
 
+        new_allocated_size = FFMIN(new_allocated_size, INT_MAX);
+
         if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
             d->allocated_size = 0;
             d->size = 0;