A broken index that causes non-interleaved access and has a packet size
of 0 causes an infinite loop reading 0 bytes.  Switch to assuming file
is interleaved if a broken index is detected.
---
 libavformat/avidec.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 870066e..31e9a31 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1146,7 +1146,6 @@ static int ni_prepare_read(AVFormatContext *s)
     if (i >= 0) {
         int64_t pos = best_st->index_entries[i].pos;
         pos += best_ast->packet_size - best_ast->remaining;
-        avio_seek(s->pb, pos + 8, SEEK_SET);
 
         assert(best_ast->remaining <= best_ast->packet_size);
 
@@ -1154,6 +1153,14 @@ static int ni_prepare_read(AVFormatContext *s)
         if (!best_ast->remaining)
             best_ast->packet_size =
             best_ast->remaining   = best_st->index_entries[i].size;
+        if (!best_ast->remaining) {
+            /* broken index, assume interleaved and attempt to continue */
+            av_log(s, AV_LOG_ERROR, "Broken AVI index.\n");
+            avi->stream_index = -1;
+            avi->non_interleaved = 0;
+        } else {
+            avio_seek(s->pb, pos + 8, SEEK_SET);
+        }
     }
 
     return 0;
-- 
2.9.3

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to