]> git.sesse.net Git - ffmpeg/commitdiff
avformat/aviobuf: fix checks in ffio_ensure_seekback
authorMarton Balint <cus@passwd.hu>
Sat, 19 Sep 2020 22:01:48 +0000 (00:01 +0200)
committerMarton Balint <cus@passwd.hu>
Fri, 9 Oct 2020 19:07:18 +0000 (21:07 +0200)
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 <cus@passwd.hu>
libavformat/aviobuf.c

index d94be478acc8d6fd5d2f5c8fbfe0f4eb09cd8146..aa1d6c083010473b16c6b4254b5d05f2043734de 100644 (file)
@@ -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);