PR #25568 opened by Kacper Michajłow (kasper93)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25568
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25568.patch

Fixes FATE and cleans this...


From 5c665ef225814ad8472ed6747873e3aefe97b24f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Wed, 28 Oct 2026 20:44:28 +0100
Subject: [PATCH 1/2] fate/ogg-vorbis: pipe the chained-large-comment inputs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The test read its two parts through a concat: URL built from
target_path, which is not portable and doesn't work with Windows pathes,
at least not with enough escaping sprinkled on top. Pipe both parts
straight into the framecrc run and pass the comment to -/metadata
through a pipe, so the test writes no files.

Signed-off-by: Kacper Michajłow <[email protected]>
---
 tests/fate/ogg-vorbis.mak | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/tests/fate/ogg-vorbis.mak b/tests/fate/ogg-vorbis.mak
index 51d6a9e4d6a..d009f4e8180 100644
--- a/tests/fate/ogg-vorbis.mak
+++ b/tests/fate/ogg-vorbis.mak
@@ -9,16 +9,12 @@ fate-ogg-vorbis-copy-chained-meta: CMD = run_with_temp 
"$(FFMPEG) -nostdin -hide
 
 # Chain two streams cut from the same sample, the second one with a comment
 # header larger than 64 KiB (as with embedded cover art).
-FATE_OGG_COPY_VORBIS-$(call FRAMECRC, OGG FFMETADATA, VORBIS, OGG_MUXER 
CONCAT_PROTOCOL) += fate-ogg-vorbis-chained-large-comment
+FATE_OGG_COPY_VORBIS-$(call FRAMECRC, OGG, VORBIS, OGG_MUXER) += 
fate-ogg-vorbis-chained-large-comment
 fate-ogg-vorbis-chained-large-comment: CMD = \
-    cleanfiles="$${cleanfiles} $${outfile}.txt $${outfile}.1.ogg 
$${outfile}.2.ogg"; \
-    printf ";FFMETADATA1\ncomment=%070000d\n" 0 > "$${outfile}.txt" && \
-    ffmpeg -i $(TARGET_SAMPLES)/vorbis/moog_small.ogg -c copy -t 0.5 -fflags 
+bitexact \
-        -y "$$(target_path "$${outfile}.1.ogg")" && \
-    ffmpeg -i $(TARGET_SAMPLES)/vorbis/moog_small.ogg -i "$$(target_path 
"$${outfile}.txt")" \
-        -map 0 -map_metadata 1 -c copy -t 0.5 -fflags +bitexact -serial_offset 
1 \
-        -y "$$(target_path "$${outfile}.2.ogg")" && \
-    framecrc -i "concat:$$(target_path "$${outfile}.1.ogg")|$$(target_path 
"$${outfile}.2.ogg")" -c copy
+    { ffmpeg -i $(TARGET_SAMPLES)/vorbis/moog_small.ogg -c copy -t 0.5 -fflags 
+bitexact -f ogg - && \
+      printf "comment=%070000d" 0 | ffmpeg -i 
$(TARGET_SAMPLES)/vorbis/moog_small.ogg -/metadata pipe: \
+        -c copy -t 0.5 -fflags +bitexact -serial_offset 1 -f ogg -; } | \
+    framecrc -i - -c copy
 
 FATE_OGG_VORBIS_PROBE-$(call DEMDEC, OGG, VORBIS) += 
fate-ogg-vorbis-initial-padding-chained
 fate-ogg-vorbis-initial-padding-chained: CMD = ffprobe_demux -of default 
-show_entries stream=codec_name,initial_padding 
$(TARGET_SAMPLES)/ogg-vorbis/chained-meta.ogg
-- 
2.54.0


From d087ebb7a17274f5586c3d2c4888a31af0f83a0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Wed, 28 Oct 2026 21:00:56 +0100
Subject: [PATCH 2/2] avformat/oggparsevorbis: reuse fixup_vorbis_headers() for
 chained streams
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Kacper Michajłow <[email protected]>
---
 libavformat/oggparsevorbis.c | 70 +++++++++---------------------------
 1 file changed, 17 insertions(+), 53 deletions(-)

diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 18160ec3ddb..5a23fc44502 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -213,12 +213,6 @@ struct oggvorbis_private {
     unsigned int len[3];
     unsigned char *packet[3];
     AVVorbisParseContext *vp;
-    uint8_t *header;
-    int header_size;
-    uint8_t *comment;
-    int comment_size;
-    uint8_t *setup;
-    int setup_size;
     int64_t bos_page_pos;
     int ts_offset;
     int64_t last_page_granule;
@@ -273,10 +267,6 @@ static void vorbis_cleanup(AVFormatContext *s, int idx)
         av_vorbis_parse_free(&priv->vp);
         for (i = 0; i < 3; i++)
             av_freep(&priv->packet[i]);
-
-        av_freep(&priv->header);
-        av_freep(&priv->comment);
-        av_freep(&priv->setup);
     }
 }
 
@@ -462,7 +452,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
     struct oggvorbis_private *priv = os->private;
     int duration, flags = 0;
     int bos, skip_packet = 0;
-    int ret, new_extradata_size;
+    int ret;
 
     if (os->psize == 0)
         return AVERROR_INVALIDDATA;
@@ -567,12 +557,12 @@ static int vorbis_packet(AVFormatContext *s, int idx)
         if (ret < 0)
             return ret;
 
-        ret = av_reallocp(&priv->header, os->psize);
+        ret = av_reallocp(&priv->packet[0], os->psize);
         if (ret < 0)
             return ret;
 
-        memcpy(priv->header, os->buf + os->pstart, os->psize);
-        priv->header_size = os->psize;
+        memcpy(priv->packet[0], os->buf + os->pstart, os->psize);
+        priv->len[0] = os->psize;
 
         skip_packet = 1;
     }
@@ -582,24 +572,24 @@ static int vorbis_packet(AVFormatContext *s, int idx)
         if (ret < 0)
             return ret;
 
-        ret = av_reallocp(&priv->comment, os->psize);
+        ret = av_reallocp(&priv->packet[1], os->psize);
         if (ret < 0)
             return ret;
 
-        memcpy(priv->comment, os->buf + os->pstart, os->psize);
-        priv->comment_size = os->psize;
+        memcpy(priv->packet[1], os->buf + os->pstart, os->psize);
+        priv->len[1] = os->psize;
 
         flags = 0;
         skip_packet = 1;
     }
 
     if (flags & VORBIS_FLAG_SETUP) {
-        ret = av_reallocp(&priv->setup, os->psize);
+        ret = av_reallocp(&priv->packet[2], os->psize);
         if (ret < 0)
             return ret;
 
-        memcpy(priv->setup, os->buf + os->pstart, os->psize);
-        priv->setup_size = os->psize;
+        memcpy(priv->packet[2], os->buf + os->pstart, os->psize);
+        priv->len[2] = os->psize;
 
         skip_packet = 1;
     }
@@ -607,40 +597,14 @@ static int vorbis_packet(AVFormatContext *s, int idx)
 
     /* All three headers for the new chained stream have been collected;
      * pack them into new extradata to be attached to the next data packet. */
-    if (priv->header && priv->comment && priv->setup) {
-        uint64_t total_size = (uint64_t)priv->header_size + priv->comment_size 
+
-                              priv->setup_size;
-        uint8_t *p;
-
-        /* Use Xiph lacing like vorbis_header() does: 16-bit sizes cannot
-         * describe headers larger than 64 KiB, e.g. a comment header with
-         * embedded cover art. */
-        if (total_size + total_size / 255 + 3 > INT_MAX)
-            return AVERROR_INVALIDDATA;
-        new_extradata_size = 1 + priv->header_size / 255 + 1 +
-                             priv->comment_size / 255 + 1 + total_size;
-
-        ret = av_reallocp(&os->new_extradata, new_extradata_size);
-        if (ret < 0)
+    if (priv->packet[0] && priv->packet[1] && priv->packet[2]) {
+        av_freep(&os->new_extradata);
+        ret = fixup_vorbis_headers(s, priv, &os->new_extradata);
+        if (ret < 0) {
+            os->new_extradata_size = 0;
             return ret;
-
-        os->new_extradata_size = new_extradata_size;
-        p     = os->new_extradata;
-        *p++  = 2;
-        p    += av_xiphlacing(p, priv->header_size);
-        p    += av_xiphlacing(p, priv->comment_size);
-        memcpy(p, priv->header, priv->header_size);
-        p    += priv->header_size;
-        memcpy(p, priv->comment, priv->comment_size);
-        p    += priv->comment_size;
-        memcpy(p, priv->setup, priv->setup_size);
-
-        av_freep(&priv->header);
-        priv->header_size = 0;
-        av_freep(&priv->comment);
-        priv->comment_size = 0;
-        av_freep(&priv->setup);
-        priv->setup_size = 0;
+        }
+        os->new_extradata_size = ret;
 
         av_vorbis_parse_free(&priv->vp);
         priv->vp = av_vorbis_parse_init(os->new_extradata, 
os->new_extradata_size);
-- 
2.54.0

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

Reply via email to