From patchwork Mon Jun 17 21:05:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodecs Bela X-Patchwork-Id: 13592 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 41A64449B39 for ; Tue, 18 Jun 2019 00:57:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1AADE68A7A7; Tue, 18 Jun 2019 00:57:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.vivacom.hu (mail.vivacom.hu [185.92.116.29]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD0DF689DA0 for ; Tue, 18 Jun 2019 00:57:35 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mail.vivacom.hu (Postfix) with ESMTP id 4348185105 for ; Mon, 17 Jun 2019 23:57:02 +0200 (CEST) X-Virus-Scanned: amavisd-new at example.com Received: from mail.vivacom.hu ([127.0.0.1]) by localhost (mail.vivacom.intra [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DMZPpMIx19DZ for ; Mon, 17 Jun 2019 23:56:59 +0200 (CEST) Received: from [192.168.0.12] (77-234-79-34.pool.digikabel.hu [77.234.79.34]) by mail.vivacom.hu (Postfix) with ESMTPA id BA86A2496E3 for ; Mon, 17 Jun 2019 23:05:22 +0200 (CEST) To: FFmpeg development discussions and patches From: Bodecs Bela Message-ID: <19b3fdd0-734f-f4a6-168c-707fc8a24b6a@vivanet.hu> Date: Mon, 17 Jun 2019 23:05:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 Content-Language: hu Subject: [FFmpeg-devel] [PATCH] av_format/hlsenc: fix %v handling by format_name function 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi All, When multiple variant streams are specified by var_stream_map option, %v placeholder in various names ensures that each variant has its unique names. Most of %v handlng is done in format_name function. Currently in this function the result buffer is the same as the input pattern buffer, so you must allocate it before calling format_name function. It also means, that it is silently assumed that the result string will NOT be longer that the pattern string. It is true most of the time, because %v may appear only once in the pattern string and number of variant streams is less than 100 in practical cases. But theoretically it will fail if specified number of variant streams is greater than 100 (i.e. longer than 2 digits). This patch fixes this behaviour by altering format_name function to allocate the result buffer and return it to the caller. Please, review this patch. best, Bela From 6377ebee8a106a9684d41b270c7d6c8e57cd3e7b Mon Sep 17 00:00:00 2001 From: Bela Bodecs Date: Mon, 17 Jun 2019 14:31:36 +0200 Subject: [PATCH] av_format/hlsenc: fix %v handling by format_name function When multiple variant streams are specified by var_stream_map option, %v placeholder in various names ensures that each variant has its unique names. Most of %v handlng is done in format_name function. Currently in this function the result buffer is the same as the input pattern buffer, so you must allocate it before calling format_name function. It also means, that it is silently assumed that the result string will NOT be longer that the pattern string. It is true most of the time, because %v may appear only once in the pattern string and number of variant streams is less than 100 in practical cases. But theoretically it will fail if specified number of variant streams is greater than 100. This patch fixes this behaviour by altering format_name function to allocate the result buffer and return it to the caller. Signed-off-by: Bela Bodecs --- libavformat/hlsenc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 9884f74d51..ebe1ab62e5 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1761,33 +1761,34 @@ fail: return ret; } -static int format_name(char *buf, int buf_len, int index) +static int format_name(const char *buf, char **s, int index) { const char *proto, *dir; - char *orig_buf_dup = NULL, *mod_buf = NULL, *mod_buf_dup = NULL; + char *orig_buf_dup = NULL, *mod_buf_dup = NULL; int ret = 0; - if (!av_stristr(buf, "%v")) - return ret; - orig_buf_dup = av_strdup(buf); if (!orig_buf_dup) { ret = AVERROR(ENOMEM); goto fail; } - if (replace_int_data_in_filename(&mod_buf, orig_buf_dup, 'v', index) < 1) { + if (!av_stristr(buf, "%v")) { + *s = orig_buf_dup; + return ret; + } + + if (replace_int_data_in_filename(s, orig_buf_dup, 'v', index) < 1) { ret = AVERROR(EINVAL); goto fail; } - av_strlcpy(buf, mod_buf, buf_len); proto = avio_find_protocol_name(orig_buf_dup); dir = av_dirname(orig_buf_dup); /* if %v is present in the file's directory, create sub-directory */ if (av_stristr(dir, "%v") && proto && !strcmp(proto, "file")) { - mod_buf_dup = av_strdup(buf); + mod_buf_dup = av_strdup(*s); if (!mod_buf_dup) { ret = AVERROR(ENOMEM); goto fail; @@ -1803,7 +1804,6 @@ static int format_name(char *buf, int buf_len, int index) fail: av_freep(&orig_buf_dup); av_freep(&mod_buf_dup); - av_freep(&mod_buf); return ret; } @@ -2634,7 +2634,7 @@ static int hls_init(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - ret = format_name(vs->m3u8_name, strlen(s->url) + 1, i); + ret = format_name(s->url, i, vs->m3u8_name); if (ret < 0) goto fail;