Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "softworkz ." <softworkz-at-hotmail.com@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Timothy Allen <tim@treehouse.org.za>
Subject: Re: [FFmpeg-devel] [PATCH] Percent-encode URL paths in HLS playlists
Date: Fri, 23 May 2025 21:36:45 +0000
Message-ID: <DM8P223MB0365375FB7652A0D3ABFB48ABA98A@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <04d464cf3931b2ebda4915b341317bc8ff1cc7e2.camel@treehouse.org.za>



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Timothy
> Allen via ffmpeg-devel
> Sent: Freitag, 23. Mai 2025 16:53
> To: ffmpeg-devel@ffmpeg.org
> Cc: Timothy Allen <tim@treehouse.org.za>
> Subject: [FFmpeg-devel] [PATCH] Percent-encode URL paths in HLS playlists
> 
> This commit closes trac ticket 10679.
> 
> Signed-off-by: Timothy Allen <tim@treehouse.org.za>
> ---
>  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++) {

What about the slash:

> +        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])
> +        {

Space must be %20. The plus sign is only used for encoding form fields.

> +            buf[p++] = '+';
> +        } else
> +        {

Check buffer size:

> +            buf[p++] = '%';


Use HEX for upper case:

> +            buf[p++] = hex[url[i] >> 4];
> +            buf[p++] = hex[url[i] & 15];

> +            }
> +    }

Check buffer size:

> +    buf[p] = '\0';
> +
> +    return 0;
> +}
> +


Please also check behavior with signed/unsigned char, I'm not sure 
whether the shifts are always right.

As a tip: using AVBPrint for building the string might be easier.
HLS URLs can be pretty long sometimes.

Regards
sw
_______________________________________________
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".

  parent reply	other threads:[~2025-05-23 21:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-23 14:53 Timothy Allen via ffmpeg-devel
2025-05-23 20:31 ` Marton Balint
2025-05-23 21:05   ` softworkz .
2025-05-23 21:36 ` softworkz . [this message]
2025-05-24 16:32 ` Rémi Denis-Courmont

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM8P223MB0365375FB7652A0D3ABFB48ABA98A@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM \
    --to=softworkz-at-hotmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=tim@treehouse.org.za \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git