[FFmpeg-devel] [PATCH] avformat/hlsenc: fix segfault when using -hls_segment_type fmp4 with -hls_segment_filename

Steven Liu lingjiujianke at gmail.com
Sat Sep 16 03:37:22 EEST 2017


2017-09-16 7:16 GMT+08:00 Aman Gupta <ffmpeg at tmm1.net>:
> From: Aman Gupta <aman at tmm1.net>
>
> previously, specifying -hls_segment_filename meant
> s->base_output_dirname was never set, causing a segfault:
>
> (lldb) bt
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
>   * frame #0: 0x00007fffbf7d82d0 libsystem_platform.dylib`_platform_strcmp + 80
>     frame #1: 0x00000001005f4dcf libavformat.57.dylib`io_open_default(s=0x000000010481cc00, pb=0x0000000104806020, url=0x0000000000000000, flags=2, options=0x0000000000000000) at options.c:107
>     frame #2: 0x0000000100528968 libavformat.57.dylib`hls_mux_init(s=0x000000010481cc00) at hlsenc.c:595
>     frame #3: 0x00000001005273cb libavformat.57.dylib`hls_write_header(s=0x000000010481cc00) at hlsenc.c:1518
>     frame #4: 0x00000001005c08d0 libavformat.57.dylib`write_header_internal(s=0x000000010481cc00) at mux.c:486
>     frame #5: 0x00000001005c0774 libavformat.57.dylib`avformat_write_header(s=0x000000010481cc00, options=0x00000001029026e8) at mux.c:539
> ---
>  libavformat/hlsenc.c | 45 +++++++++++++++++++++++----------------------
>  1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 895aa41bc3..3a9a235514 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1441,32 +1441,33 @@ static int hls_write_header(AVFormatContext *s)
>          } else {
>              av_strlcat(hls->basename, pattern, basename_size);
>          }
> +    }
>
> -        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);
> -                goto fail;
> -            }
> -            av_strlcpy(hls->base_output_dirname, hls->fmp4_init_filename, fmp4_init_filename_len);
> -        } else {
> -            hls->base_output_dirname = av_malloc(basename_size);
> -            if (!hls->base_output_dirname) {
> -                ret = AVERROR(ENOMEM);
> -                goto fail;
> -            }
> +    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);
> +            goto fail;
> +        }
> +        av_strlcpy(hls->base_output_dirname, hls->fmp4_init_filename, fmp4_init_filename_len);
> +    } else {
> +        hls->base_output_dirname = av_malloc(basename_size);
> +        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 (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, 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);
>          }
>      }
> +
>      if (!hls->use_localtime) {
>          ret = sls_flag_check_duration_size_index(hls);
>          if (ret < 0) {
> --
> 2.13.5 (Apple Git-94)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


LGTM


More information about the ffmpeg-devel mailing list