From patchwork Sat May 9 19:15:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19587 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 03F894499FD for ; Sat, 9 May 2020 22:15:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E09E268A14B; Sat, 9 May 2020 22:15:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB2C9689E39 for ; Sat, 9 May 2020 22:15:41 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id 50so5337899wrc.11 for ; Sat, 09 May 2020 12:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jk62F+XV+ceM2op2a1534XiltqsIbgr8EizWjW32zPI=; b=Yu184gJ4O/ot2qZLVOefFmBfcAbL0bArz+HFYtZWZH49eiNP5uqZ9YnIOUlXcXGXo7 bvYJHLMgMxQeOr5w4ACzf5Ok6OIk/CF1TxcnCNzWRagxN/xZOHuxZkpKU3i7oUnpuz6t rPyZLc1E8L7IjuXrl+xOHWQtgV6rhwzR6V1rY1sgC3RGn2x4E+CzXWa7tWpYygqwQTnH CKVOYF9sbbzum0qliLU2KhDjRL9HnjUjLbKmptU7PZNs1AAGvcnTGRLJcpMyKcZYFEfV ajjC9ztLJ7RO2S5yxOQ2h9Z6LurtrOiE3nCzB8dragk32duWBnDDU+2XmmO6N3wX6qBd L9UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jk62F+XV+ceM2op2a1534XiltqsIbgr8EizWjW32zPI=; b=g0M5vk6dGX/BXRCEFsJ2HW9s53LsQXRJ+UwBu2TbusOFsdkgH/hRz/O2UtjKkg96Mp GTl3Sa6mMlavVD2zbk0Q2RdinyuiR6XhPbjbuYgbCrCWWlsu9opkvmE2/aNSHDS3FtKe Mhz6vFe8hiMAKjTcSDgIuiyzByuszasuvaU/Kmnr2BmDW668GKMUekHRsdJ1QbFjCxv7 WJD8PCrmh66lO7BjtXdyvaSGaaX7WYLjZwnHoDMRJ/aFObucQQAhEu9LYknG7O8pZG/B JA1tYWmW9Ssyht8jnTizPEwhZcpRSsPv8m0oc8C2PW6s8nv4WlQU69tGVrUtRhZhY1eb LNJQ== X-Gm-Message-State: AGi0PuaHACjLNf6Ryw8XgzLUBIY71EPMvLq2TNYYSv4Rux2RYdB2lQg4 dZSSagwMVGmeaanakfIsiTCOV6jk X-Google-Smtp-Source: APiQypJwCKKe/OTO6m9kMUH4O10THdJVRxyCHJaX0hQoKYfevFH8d2sKcatiJ1DiVgppTfPcT2VA7A== X-Received: by 2002:adf:e4cf:: with SMTP id v15mr9436883wrm.43.1589051740936; Sat, 09 May 2020 12:15:40 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id w9sm10055217wrc.27.2020.05.09.12.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 12:15:40 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 May 2020 21:15:09 +0200 Message-Id: <20200509191509.9812-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200509191509.9812-1-andreas.rheinhardt@gmail.com> References: <20200509191509.9812-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] avformat/hlsenc: Simplify setting base_output_dirname 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- The usage of fmp4_init_filename_len is weird: It is basically used for two different purposes: The length of vs->fmp4_init_filename_len and the length of vs->base_output_dirname (this name is btw misleading because it is not a dirname at all). And given that it's scope is the whole function, the second time vs->fmp4_init_filename was allocated it also contained enough space to contain the whole of vs->m3u8_name. Furthermore, there seems to be a misconception in the way the fmp4_init_filename_len is calculated in case of more than one varstreams: It is incremented by strlen("_%d"), yet the string is not built by inserting "_%d" into the other string; instead if no %v is present in the string and if there is more than varstream, then it is created by inserting "_%d", where %d is replace by the actual index of the varstream. And this can take more than three bytes. But it is not dangerous: fmp4_init_filename_len is incremented by strlen("_%d") on every iteration of the loop. I also pondered using av_append_path_component() in the case that p is not NULL below; yet this might swallow a "/" and I don't know if it would make a difference. (Is it actually allowed to use an absolute path for hls->fmp4_init_filename? If one does so, said path will still be treated as relative to the directory of vs->m3u8_name.) I can also give vs->fmp4_init_filename a similar treatment; yet before doing so I'd like to know if it is intentional that a "%v" in hls->fmp4_init_filename only gets replaced if there is more than one varstream (in other cases a %v also gets replaced when one only has one varstream). libavformat/hlsenc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index d80852739e..be54957e9d 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2908,24 +2908,18 @@ static int hls_init(AVFormatContext *s) return ret; } - fmp4_init_filename_len = strlen(vs->m3u8_name) + - strlen(vs->fmp4_init_filename) + 1; - - vs->base_output_dirname = av_malloc(fmp4_init_filename_len); - if (!vs->base_output_dirname) - return AVERROR(ENOMEM); - - av_strlcpy(vs->base_output_dirname, vs->m3u8_name, - fmp4_init_filename_len); - p = strrchr(vs->base_output_dirname, '/'); + p = strrchr(vs->m3u8_name, '/'); if (p) { - *(p + 1) = '\0'; - av_strlcat(vs->base_output_dirname, vs->fmp4_init_filename, - fmp4_init_filename_len); + char tmp = *(++p); + *p = '\0'; + vs->base_output_dirname = av_asprintf("%s%s", vs->m3u8_name, + vs->fmp4_init_filename); + *p = tmp; } else { - av_strlcpy(vs->base_output_dirname, vs->fmp4_init_filename, - fmp4_init_filename_len); + vs->base_output_dirname = av_strdup(vs->fmp4_init_filename); } + if (!vs->base_output_dirname) + return AVERROR(ENOMEM); } }