Skip to content

Commit

Permalink
avformat/aviobuf: fix checks in ffio_ensure_seekback
Browse files Browse the repository at this point in the history
The new buf_size was detemined too conservatively, maybe because of the
off-by-one issue which was fixed recently in fill_buffer. We can safely
substract 1 more from the new buffer size, because max_buffer_size space must
only be guaranteed when we are reading the last byte of the requested window.

Comparing the new buf_size against filled did not make a lot of sense, what
makes sense is that we want to reallocate the buffer if the new buf_size is
bigger than the old, therefore the change in the check.

Signed-off-by: Marton Balint <[email protected]>
  • Loading branch information
cus committed Oct 9, 2020
1 parent 6d972be commit a3943c4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libavformat/aviobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,9 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
if (buf_size <= s->buf_end - s->buf_ptr)
return 0;

buf_size += s->buf_ptr - s->buffer + max_buffer_size;
buf_size += s->buf_ptr - s->buffer + max_buffer_size - 1;

if (buf_size < filled || s->seekable || !s->read_packet)
if (buf_size <= s->buffer_size || s->seekable || !s->read_packet)
return 0;
av_assert0(!s->write_flag);

Expand Down

0 comments on commit a3943c4

Please sign in to comment.