]> git.sesse.net Git - ffmpeg/commitdiff
avformat/mlvdec: Check for existence of AVIOContext before using it
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 9 Aug 2020 23:32:42 +0000 (01:32 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 18 Aug 2020 12:18:18 +0000 (14:18 +0200)
The mlv demuxer supports input split into multiple files; if invalid
data is encountered when parsing one of the subsequent files, that file
is closed. But at this point some index entries belonging to this file
might already have been added. In this case, the read_packet function
might try to use the AVIOContext (which is NULL) to read data which will
of course crash. This commit fixes this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/mlvdec.c

index 03aed7102444fae5113c377113d27b72e4071a24..7c7ced7f76ba4c5c7d9ff5b27ad15f7492b5409a 100644 (file)
@@ -411,6 +411,10 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
     }
 
     pb = mlv->pb[st->index_entries[index].size];
+    if (!pb) {
+        ret = FFERROR_REDO;
+        goto next_packet;
+    }
     avio_seek(pb, st->index_entries[index].pos, SEEK_SET);
 
     avio_skip(pb, 4); // blockType
@@ -439,12 +443,14 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
     pkt->stream_index = mlv->stream_index;
     pkt->pts = mlv->pts;
 
+    ret = 0;
+next_packet:
     mlv->stream_index++;
     if (mlv->stream_index == avctx->nb_streams) {
         mlv->stream_index = 0;
         mlv->pts++;
     }
-    return 0;
+    return ret;
 }
 
 static int read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)