From patchwork Wed Oct 25 23:54:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 5693 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp192453jah; Wed, 25 Oct 2017 16:55:23 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Tw6oXF2I+2KgKFo09qlnWns0cMg9nPP9gaGeNY/JabZyI08qF0apN7f6H9/FudE35VTENT X-Received: by 10.28.97.194 with SMTP id v185mr3323942wmb.117.1508975723523; Wed, 25 Oct 2017 16:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508975723; cv=none; d=google.com; s=arc-20160816; b=RxQUgvTF/JEPSgog/r+jH0uH/S4rMSLwcBXS4ECTRli6Kw6AEpMV2R6uFcva4kfCeo gYOltG1stsSTSREnWw/67htcvudkiBGTABe7ZeUD4UstOFCXH9XQ2F/C55ez4f77JTiu /nnIox4Lj92yu6vjllDMe1PIaHv50zN5pggb98jSEto11mtKLayKLximEXX6o6rbUFeq y14pxQ46egp+SuLR6Tl8Rkx1D6Zav0iLsskVG31YBFoiA/wCb+CYDwOPRpkHp34ssmFf 92zbBo6EHM57BzwyUI4oo1jxPDjbIqrZXLkG8/PLSAYQVMFmNBxtSxO2ymyuDwRYyez5 N2kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:message-id:date:to:from :delivered-to:arc-authentication-results; bh=Z+4oxKHTNho+UPo21gNFSUVeUA8qwhm3Na0lnoQJZWA=; b=IxtL8+5mspMnC69/ayAPVgCpISCWzr4APOnTI9vq8gafpNMz6E9MPzjI4gTbuEFD4Y 3BO4hpndYW0LTTsgyCLF+/LYdNcGPqb9Pir0MK2gW81ZZkWHpRw9RNYg5dOsqKeCJXrq Mr+tkM+/tHdONB67zaRwbYyxfgUnPjek21WqFqJGpnqrTZSGGd3AJPEBFXoQclFv/WJC HAwBK2jH/9DGSU2N01PUU98LyBBnSGPXk+vqUUpP5kE03vPDaaRjacc2aQYMaVjshwNB 204MrTBLk4mXsldrgHeD50xVwzjYLKkf7AEcOYGiB1idxX0hsjr9wzErDryAkZxrcPLp dmpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i78si23465wmf.178.2017.10.25.16.55.22; Wed, 25 Oct 2017 16:55:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C443868A54E; Thu, 26 Oct 2017 02:55:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbg181.qq.com (SMTPBG181.QQ.COM [119.147.193.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6574168A512 for ; Thu, 26 Oct 2017 02:55:07 +0300 (EEST) X-QQ-mid: bizesmtp4t1508975674tay1a7o82 Received: from localhost (unknown [114.245.24.93]) by esmtp4.qq.com (ESMTP) with id ; Thu, 26 Oct 2017 07:54:33 +0800 (CST) X-QQ-SSF: 01100000004000F0FI60B00A0000000 X-QQ-FEAT: 1elLNeR01bZuf2EOa/8QfU+/Mbqp56t+7EtBpAOj7YPrezaqNrLsm4YEGjhD2 3QtZkR+N2rkk1DP7gFZwDTidZATowN7xap4+WhAL8/UbmAct4FrKvfJZ0+G7q+3gpwRSFaB i/B8xh4sfDCYUaLy92F/3cASELK4RRIvS68clVFXz6+WT2D2/1cbOsYIkrCwa0mXXHFPwV9 Bl2OG4flEK5IRsUrqb5yGjSW6mShgfP9w5DC9AcBSG46/0hgW1nMaHfg9WQfFULBqVsIqQ5 +zUynQa3z/ZiGPb1eiJEUdXxE= X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Oct 2017 07:54:32 +0800 Message-Id: <20171025235432.35640-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.11.0 (Apple Git-81) X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: fix base_output_dirname is null when basename_size is 0 bug X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" fix ticket id: #6777 when use argument hls_segment_filename, the basename_size will be 0 Signed-off-by: Steven Liu --- 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); } }