[FFmpeg-devel,3/3] libavformat/aviobuf: don't treat 0 as EOF

Submitted by Daniel Kucera on Oct. 13, 2017, 7:03 p.m.

Details

Message ID 20171013190349.24112-3-daniel.kucera@gmail.com
State New
Headers show

Commit Message

Daniel Kucera Oct. 13, 2017, 7:03 p.m.
Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
---
 libavformat/aviobuf.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer Oct. 13, 2017, 10:24 p.m.
On Fri, Oct 13, 2017 at 09:03:49PM +0200, Daniel Kucera wrote:
> Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
> ---
>  libavformat/aviobuf.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)

with this

make -j12 fate-wtv-demux

infinite loops

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 636cb46161..0d4eb051e1 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -572,13 +572,14 @@  static void fill_buffer(AVIOContext *s)
     if (s->read_packet)
         len = s->read_packet(s->opaque, dst, len);
     else
-        len = 0;
-    if (len <= 0) {
+        len = AVERROR_EOF;
+    if (len == AVERROR_EOF) {
         /* do not modify buffer if EOF reached so that a seek back can
            be done without rereading data */
         s->eof_reached = 1;
-        if (len < 0)
-            s->error = len;
+    } else if (len < 0) {
+        s->eof_reached = 1;
+        s->error= len;
     } else {
         s->pos += len;
         s->buf_ptr = dst;
@@ -646,13 +647,16 @@  int avio_read(AVIOContext *s, unsigned char *buf, int size)
                 // bypass the buffer and read data directly into buf
                 if(s->read_packet)
                     len = s->read_packet(s->opaque, buf, size);
-
-                if (len <= 0) {
+                else
+                    len = AVERROR_EOF;
+                if (len == AVERROR_EOF) {
                     /* do not modify buffer if EOF reached so that a seek back can
                     be done without rereading data */
                     s->eof_reached = 1;
-                    if(len<0)
-                        s->error= len;
+                    break;
+                } else if (len < 0) {
+                    s->eof_reached = 1;
+                    s->error= len;
                     break;
                 } else {
                     s->pos += len;