[FFmpeg-devel] [PATCH] avio_read data loss with multiple calls to fill_buffer

Rob Meyers robertmeyers at google.com
Thu May 18 23:12:49 EEST 2017


avio_read may make multiple calls to fill_buffer to accumulate bytes
to fulfill a request. fill_buffer will overwrite previously read data
if it is not prepped. Added a call to 'ffio_ensure_seekback' to adjust
the s->buffer to fill_buffer's liking. This isn't necessary for the
very first call to fill_buffer, thus the "size1 != size" check.
---
 libavformat/aviobuf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 0a7c39eacd..8e9594cab8 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -648,6 +648,11 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
                     s->buf_end = s->buffer/* + len*/;
                 }
             } else {
+                if (size1 != size)
+                    /* this call will ensure fill_buffer will not overwrite previously
+                    read data. */
+                    ffio_ensure_seekback(s, size1);
+
                 fill_buffer(s);
                 len = s->buf_end - s->buf_ptr;
                 if (len == 0)
-- 
2.13.0.303.g4ebf302169-goog



More information about the ffmpeg-devel mailing list