From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 631C44C2B6 for ; Fri, 23 May 2025 20:34:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id DF10268DF85; Fri, 23 May 2025 23:34:49 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 019E768DEA6 for ; Fri, 23 May 2025 23:34:43 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 996DFEB75D for ; Fri, 23 May 2025 22:31:30 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DUexAvA0biJ2 for ; Fri, 23 May 2025 22:31:28 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 95BCEEB75B for ; Fri, 23 May 2025 22:31:27 +0200 (CEST) Date: Fri, 23 May 2025 22:31:27 +0200 (CEST) From: Marton Balint To: Timothy Allen via ffmpeg-devel In-Reply-To: <04d464cf3931b2ebda4915b341317bc8ff1cc7e2.camel@treehouse.org.za> Message-ID: <5018f03c-8673-17c3-23d2-50e53dd5effc@passwd.hu> References: <04d464cf3931b2ebda4915b341317bc8ff1cc7e2.camel@treehouse.org.za> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] Percent-encode URL paths in HLS playlists X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 23 May 2025, Timothy Allen via ffmpeg-devel wrote: > This commit closes trac ticket 10679. And what if the M3U8 is referencing absolute URLs with scheme? Or is using a data URI? Or if it is a local DOS path? What if the URL is already percent encoded? This issue is not trivial to fix, so I really meant it when I wrote that its worth checking what heuristics other software is using for this issue. Thanks, Marton > > Signed-off-by: Timothy Allen > --- > libavformat/hls.c | 9 +++++++++ > libavformat/url.c | 35 +++++++++++++++++++++++++++++++++++ > libavformat/url.h | 9 +++++++++ > 3 files changed, 53 insertions(+) > > diff --git a/libavformat/hls.c b/libavformat/hls.c > index c7b655c83c..49436d8184 100644 > --- a/libavformat/hls.c > +++ b/libavformat/hls.c > @@ -1021,6 +1021,15 @@ static int parse_playlist(HLSContext *c, const char *url, > seg->key = NULL; > } > > + ff_percent_encode_url(tmp_str, sizeof(tmp_str), line); > + if (!tmp_str[0]) { > + ret = AVERROR_INVALIDDATA; > + if (seg->key) > + av_free(seg->key); > + av_free(seg); > + goto fail; > + } > + strcpy(line, av_strdup(tmp_str)); > ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, line); > if (!tmp_str[0]) { > ret = AVERROR_INVALIDDATA; > diff --git a/libavformat/url.c b/libavformat/url.c > index d5dd6a4666..69d68d4248 100644 > --- a/libavformat/url.c > +++ b/libavformat/url.c > @@ -324,6 +324,41 @@ int ff_make_absolute_url(char *buf, int size, const char *base, > return ff_make_absolute_url2(buf, size, base, rel, HAVE_DOS_PATHS); > } > > +int ff_percent_encode_url(char *buf, int size, const char *url) > +{ > + const char *hex = "0123456789abcdef"; > + > + av_assert0(url); > + > + int p = 0; > + int len = strlen(url); > + for (int i = 0; i < len; i++) { > + if (i + 1 < len && ':' == url[i] && '/' == url[i+1]) > + buf[p++] = url[i]; > + else if (('a' <= url[i] && url[i] <= 'z') > + || ('A' <= url[i] && url[i] <= 'Z') > + || ('0' <= url[i] && url[i] <= '9') > + || '/' == url[i] || '.' == url[i] || '~' == url[i] > + || '-' == url[i] || '_' == url[i] || '+' == url[i] > + || '?' == url[i] || '=' == url[i] || '&' == url[i] > + || '#' == url[i]) > + { > + buf[p++] = url[i]; > + } else if (' ' == url[i]) > + { > + buf[p++] = '+'; > + } else > + { > + buf[p++] = '%'; > + buf[p++] = hex[url[i] >> 4]; > + buf[p++] = hex[url[i] & 15]; > + } > + } > + buf[p] = '\0'; > + > + return 0; > +} > + > AVIODirEntry *ff_alloc_dir_entry(void) > { > AVIODirEntry *entry = av_mallocz(sizeof(AVIODirEntry)); > diff --git a/libavformat/url.h b/libavformat/url.h > index 0784d77b64..85f94f06ce 100644 > --- a/libavformat/url.h > +++ b/libavformat/url.h > @@ -331,6 +331,15 @@ int ff_make_absolute_url2(char *buf, int size, const char *base, > int ff_make_absolute_url(char *buf, int size, const char *base, > const char *rel); > > +/** > + * Percent-encode a URL, to avoid it being incorrectly parsed. > + * > + * @param buf the buffer where output absolute url is written > + * @param size the size of buf > + * @param url the url to encode > + */ > +int ff_percent_encode_url(char *buf, int size, const char *url); > + > /** > * Allocate directory entry with default values. > * > -- > 2.43.0 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".