PR #24802 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24802
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24802.patch

HTTP input with `Content-Type: audio/L16;rate=44100;channels=2` currently 
reaches the PCM demuxer as `audio/L16`, causing it to reject the missing sample 
rate. This regression was verified at 0cd2e7dcfbc8 against its working parent 
f780e07149bc.

Restore the full HTTP Content-Type value, following bubbleguuum’s proposed fix 
and preserving their authorship. Keep parameter removal in the private probing 
copy in `av_probe_input_buffer2()` and trim trailing whitespace there. This 
preserves HLS detection when whitespace precedes the semicolon while retaining 
exact MIME-type comparisons in `hls_probe()`.

Fixes #24022.

Validation on Linux/aarch64 with GCC 13.3:

- Reproduced the original error on master 09f879b07428; verified correct PCM 
codec, rate and channel count with this change.
- Passed 17 loopback HTTP cases covering LPCM parameters and whitespace, 
missing-rate rejection, all four accepted HLS MIME types, and rejection of an 
invalid MIME-type suffix.
- Passed the enabled `fate-libavformat` tests: mkdir, rename, http-status-line, 
noproxy, url and seek_utils.
- Tested an adapted backport on release/6.1 with the same 17 integration cases.

The [reproducer and recorded 
results](https://code.ffmpeg.org/Forgejo_Fairy/FFmpeg/src/branch/fairy/issue24022-tooling/tools/issue24022)
 generate all inputs locally. The HLS fixture uses a WAV segment with 
`extension_picky` disabled where available; playlist detection remains 
automatic.


From f768be175a6c30f1398af36a3ad80af49689dc25 Mon Sep 17 00:00:00 2001
From: bubbleguuum <[email protected]>
Date: Tue, 29 Sep 2026 21:20:28 +0000
Subject: [PATCH] avformat/http: preserve Content-Type parameters for demuxers

0cd2e7dcfbc835f4519f1b2b7da6bd902dbb0190 stripped parameters from the
exported HTTP MIME type. This makes audio/L16 fail in pcm_read_header(),
which needs the rate and optional channels parameters.

Restore the full Content-Type value as proposed in bubbleguuum's
b17dd7c2bcd151654c43c72e58d44cc49cdbcbc2. Keep parameter stripping in
av_probe_input_buffer2(), where it operates on a private copy, and trim
trailing whitespace there as well. This preserves detection of HLS URLs
without a playlist extension when whitespace precedes the semicolon,
without changing hls_probe() to accept arbitrary MIME-type prefixes.

Fixes: #24022
Assisted-by: Fairy
---
 libavformat/format.c | 11 +++++++----
 libavformat/http.c   |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavformat/format.c b/libavformat/format.c
index 45f382c2a1..3055c6e078 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -277,12 +277,15 @@ int av_probe_input_buffer2(AVIOContext *pb, const 
AVInputFormat **fmt,
 
     if (pb->av_class) {
         uint8_t *mime_type_opt = NULL;
-        char *semi;
+        uint8_t *end;
         av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type_opt);
         pd.mime_type = (const char *)mime_type_opt;
-        semi = pd.mime_type ? strchr(mime_type_opt, ';') : NULL;
-        if (semi) {
-            *semi = '\0';
+        if (mime_type_opt) {
+            /* Strip parameters and trailing whitespace for probing only. */
+            end = mime_type_opt + strcspn(mime_type_opt, ";");
+            while (end > mime_type_opt && av_isspace(end[-1]))
+                end--;
+            *end = '\0';
         }
     }
 
diff --git a/libavformat/http.c b/libavformat/http.c
index b7ae56f723..1103aa065c 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1408,7 +1408,7 @@ static int process_line(URLContext *h, char *line, int 
line_count, int *parsed_h
             }
         } else if (!av_strcasecmp(tag, "Content-Type")) {
             av_free(s->mime_type);
-            s->mime_type = av_get_token((const char **)&p, ";");
+            s->mime_type = av_strdup(p);
         } else if (!av_strcasecmp(tag, "Set-Cookie")) {
             if (parse_cookie(s, p, s->host, &s->cookie_dict))
                 av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to