[FFmpeg-devel] [PATCH 3/3] avformat/wtvdec: Forward errors when reading packet

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Aug 21 12:04:38 EEST 2019


wtvfile_read_packet did not abide by the requirements of a function
destined to read a packet: If it did not read anything, it returned
zero, which currently leads to a warning in read_packet_wrapper in
aviobuf.c. Said warning will be an av_assert2 as soon as
FF_API_OLD_AVIO_EOF_0 is zero (probably the next major version bump).
So instead forward the error code from the underlying protocol; if this
was never ever called or returned zero, return AVERROR_EOF as
read_packet_wrapper currently does.

This error/assert is triggered in the wtv-demux FATE test.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
I am not sure what the right approach is if nread and n are both zero.
Is it actually allowed for the buf_size argument to be zero? (In this
case, this scenario would happen.)

 libavformat/wtvdec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 706e8ca38d..56c54f6aba 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -71,7 +71,7 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
 {
     WtvFile *wf = opaque;
     AVIOContext *pb = wf->pb_filesystem;
-    int nread = 0;
+    int nread = 0, n = 0;
 
     if (wf->error || pb->error)
         return -1;
@@ -80,7 +80,6 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
 
     buf_size = FFMIN(buf_size, wf->length - wf->position);
     while(nread < buf_size) {
-        int n;
         int remaining_in_sector = (1 << wf->sector_bits) - (wf->position & ((1 << wf->sector_bits) - 1));
         int read_request        = FFMIN(buf_size - nread, remaining_in_sector);
 
@@ -100,7 +99,7 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
             }
         }
     }
-    return nread;
+    return nread ? nread : n ? n : AVERROR_EOF;
 }
 
 /**
-- 
2.21.0



More information about the ffmpeg-devel mailing list