[FFmpeg-devel] [PATCH] avformat/concatdec: do not close previous input if failed to open next

Zhang Rui bbcallen at gmail.com
Thu Jan 29 09:30:59 CET 2015


Avoid NULL access in next call of concat_read_packet().
---
 libavformat/concatdec.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index e109524..a593686 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -279,26 +279,31 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
 {
     ConcatContext *cat = avf->priv_data;
     ConcatFile *file = &cat->files[fileno];
+    AVFormatContext *new_avf = NULL;
     int ret;
 
-    if (cat->avf)
-        avformat_close_input(&cat->avf);
-
-    cat->avf = avformat_alloc_context();
-    if (!cat->avf)
+    new_avf = avformat_alloc_context();
+    if (!new_avf)
         return AVERROR(ENOMEM);
 
-    cat->avf->interrupt_callback = avf->interrupt_callback;
+    new_avf->interrupt_callback = avf->interrupt_callback;
 
-    if ((ret = ff_copy_whitelists(cat->avf, avf)) < 0)
+    if ((ret = ff_copy_whitelists(new_avf, avf)) < 0) {
+        avformat_close_input(&new_avf);
         return ret;
+    }
 
-    if ((ret = avformat_open_input(&cat->avf, file->url, NULL, NULL)) < 0 ||
-        (ret = avformat_find_stream_info(cat->avf, NULL)) < 0) {
+    if ((ret = avformat_open_input(&new_avf, file->url, NULL, NULL)) < 0 ||
+        (ret = avformat_find_stream_info(new_avf, NULL)) < 0) {
         av_log(avf, AV_LOG_ERROR, "Impossible to open '%s'\n", file->url);
-        avformat_close_input(&cat->avf);
-        return ret;
+        avformat_close_input(&new_avf);
+        return AVERROR_EOF;
     }
+
+    if (cat->avf)
+        avformat_close_input(&cat->avf);
+
+    cat->avf      = new_avf;
     cat->cur_file = file;
     if (file->start_time == AV_NOPTS_VALUE)
         file->start_time = !fileno ? 0 :
-- 
2.0.0



More information about the ffmpeg-devel mailing list