[FFmpeg-cvslog] avformat/hlsenc: fix base_output_dirname is null when basename_size is 0 bug

Steven Liu git at videolan.org
Sun Oct 29 06:33:17 EET 2017


ffmpeg | branch: master | Steven Liu <lq at chinaffmpeg.org> | Sun Oct 29 12:30:44 2017 +0800| [f5208307618d992ddd2d96866cf5a267c9bc7165] | committer: Steven Liu

avformat/hlsenc: fix base_output_dirname is null when basename_size is 0 bug

fix ticket id: #6777
when use argument hls_segment_filename, the basename_size will be 0

Signed-off-by: Steven Liu <lq at onvideo.cn>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f5208307618d992ddd2d96866cf5a267c9bc7165
---

 libavformat/hlsenc.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 418f153c6f..55ce800c5a 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1335,6 +1335,7 @@ static int hls_write_header(AVFormatContext *s)
     AVDictionary *options = NULL;
     int basename_size = 0;
     int vtt_basename_size = 0;
+    int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
 
     if (hls->segment_type == SEGMENT_TYPE_FMP4) {
         pattern = "%d.m4s";
@@ -1445,7 +1446,6 @@ static int hls_write_header(AVFormatContext *s)
     }
 
     if (av_strcasecmp(hls->fmp4_init_filename, "init.mp4")) {
-        int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
         hls->base_output_dirname = av_malloc(fmp4_init_filename_len);
         if (!hls->base_output_dirname) {
             ret = AVERROR(ENOMEM);
@@ -1453,19 +1453,25 @@ static int hls_write_header(AVFormatContext *s)
         }
         av_strlcpy(hls->base_output_dirname, hls->fmp4_init_filename, fmp4_init_filename_len);
     } else {
-        hls->base_output_dirname = av_malloc(basename_size);
+        if (basename_size > 0) {
+            hls->base_output_dirname = av_malloc(basename_size);
+        } else {
+            hls->base_output_dirname = av_malloc(strlen(hls->fmp4_init_filename));
+        }
         if (!hls->base_output_dirname) {
             ret = AVERROR(ENOMEM);
             goto fail;
         }
 
-        av_strlcpy(hls->base_output_dirname, s->filename, basename_size);
-        p = strrchr(hls->base_output_dirname, '/');
+        if (basename_size > 0) {
+            av_strlcpy(hls->base_output_dirname, s->filename, basename_size);
+            p = strrchr(hls->base_output_dirname, '/');
+        }
         if (p) {
             *(p + 1) = '\0';
             av_strlcat(hls->base_output_dirname, hls->fmp4_init_filename, basename_size);
         } else {
-            av_strlcpy(hls->base_output_dirname, hls->fmp4_init_filename, basename_size);
+            av_strlcpy(hls->base_output_dirname, hls->fmp4_init_filename, fmp4_init_filename_len);
         }
     }
 



More information about the ffmpeg-cvslog mailing list