Skip to content

Commit

Permalink
avformat/aviobuf: Stop restricting dynamic buffer sizes to INT_MAX/2
Browse files Browse the repository at this point in the history
This has originally been done in 568e18b
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 <[email protected]>
  • Loading branch information
mkver committed Jun 11, 2020
1 parent 88d5ae0 commit fa0bc62
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libavformat/aviobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit fa0bc62

Please sign in to comment.