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


>From 3a1a1e980662a251e9bfbf218ec930f69c76e2a3 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 11 May 2026 16:53:37 +0200
Subject: [PATCH 1/3] avformat/id3v2: Avoid temporary buffer

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/id3v2.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 44cad17d8b..66036fbdfc 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1057,18 +1057,19 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary 
**metadata,
 #endif
             if (s && (s->debug & FF_FDEBUG_ID3V2)) {
                 int64_t pos = avio_tell(pbx);
-                uint8_t *buf = av_malloc(tlen);
+                uint8_t *buf = av_malloc(tlen + 3U);
                 if (buf) {
-                    AVBPrint bp;
-                    int n = avio_read(pbx, buf, tlen);
-                    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
-                    av_bprintf(&bp, "|");
-                    for (int i = 0; i < n; i++)
-                        av_bprintf(&bp, "%c", buf[i] >= 0x20 && buf[i] < 0x7f 
? buf[i] : '.');
-                    av_bprintf(&bp, "|");
-                    av_log(NULL, AV_LOG_INFO, "ID3v2 frame %.4s (%d 
bytes):%s\n",
-                           tag, tlen, bp.str);
-                    av_bprint_finalize(&bp, NULL);
+                    int n = avio_read(pbx, buf + 1, tlen);
+                    if (n >= 0) {
+                        buf[0] = '|';
+                        for (unsigned i = 1; i <= n; i++)
+                            if (!(buf[i] >= 0x20 && buf[i] < 0x7f))
+                                buf[i] = '.';
+                        buf[n + 1] = '|';
+                        buf[n + 2] = '\0';
+                        av_log(NULL, AV_LOG_INFO, "ID3v2 frame %.4s (%d 
bytes):%s\n",
+                               tag, tlen, buf);
+                    }
                     av_free(buf);
                     avio_seek(pbx, pos, SEEK_SET);
                 }
-- 
2.52.0


>From f368a6ccba4d162c1e0fb3d73c53d2581036e83f Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 11 May 2026 16:54:27 +0200
Subject: [PATCH 2/3] avformat/id3v2: Use proper logcontext

Otherwise one could not associate log messages with inputs.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/id3v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 66036fbdfc..590eca11bf 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1067,7 +1067,7 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary 
**metadata,
                                 buf[i] = '.';
                         buf[n + 1] = '|';
                         buf[n + 2] = '\0';
-                        av_log(NULL, AV_LOG_INFO, "ID3v2 frame %.4s (%d 
bytes):%s\n",
+                        av_log(s, AV_LOG_INFO, "ID3v2 frame %.4s (%d 
bytes):%s\n",
                                tag, tlen, buf);
                     }
                     av_free(buf);
-- 
2.52.0


>From 13d53886fc6a1acabbdd3eeae457dbd5a276879b Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 11 May 2026 16:57:42 +0200
Subject: [PATCH 3/3] avformat/id3v2: Fix indentation

Forgotten after e9c372362cb736240dcd87658a027ecfb7b9d240.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/id3v2.c | 60 ++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 590eca11bf..b06b680f91 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1020,40 +1020,40 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary 
**metadata,
             }
 
 #if CONFIG_ZLIB
-                if (tcomp) {
-                    int err;
+            if (tcomp) {
+                int err;
 
-                    av_log(s, AV_LOG_DEBUG, "Compressed frame %s tlen=%d 
dlen=%ld\n", tag, tlen, dlen);
+                av_log(s, AV_LOG_DEBUG, "Compressed frame %s tlen=%d 
dlen=%ld\n", tag, tlen, dlen);
 
-                    if (tlen <= 0)
-                        goto seek;
-                    if (dlen / 32768 > tlen)
-                        goto seek;
+                if (tlen <= 0)
+                    goto seek;
+                if (dlen / 32768 > tlen)
+                    goto seek;
 
-                    av_fast_malloc(&uncompressed_buffer, 
&uncompressed_buffer_size, dlen);
-                    if (!uncompressed_buffer) {
-                        av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", 
dlen);
-                        goto seek;
-                    }
-
-                    if (!(unsync || tunsync)) {
-                        err = avio_read(pb, buffer, tlen);
-                        if (err < 0) {
-                            av_log(s, AV_LOG_ERROR, "Failed to read compressed 
tag\n");
-                            goto seek;
-                        }
-                        tlen = err;
-                    }
-
-                    err = uncompress(uncompressed_buffer, &dlen, buffer, tlen);
-                    if (err != Z_OK) {
-                        av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: 
%d\n", err);
-                        goto seek;
-                    }
-                    ffio_init_read_context(&pb_local, uncompressed_buffer, 
dlen);
-                    tlen = dlen;
-                    pbx = &pb_local.pub; // read from sync buffer
+                av_fast_malloc(&uncompressed_buffer, 
&uncompressed_buffer_size, dlen);
+                if (!uncompressed_buffer) {
+                    av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", 
dlen);
+                    goto seek;
                 }
+
+                if (!(unsync || tunsync)) {
+                    err = avio_read(pb, buffer, tlen);
+                    if (err < 0) {
+                        av_log(s, AV_LOG_ERROR, "Failed to read compressed 
tag\n");
+                        goto seek;
+                    }
+                    tlen = err;
+                }
+
+                err = uncompress(uncompressed_buffer, &dlen, buffer, tlen);
+                if (err != Z_OK) {
+                    av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", 
err);
+                    goto seek;
+                }
+                ffio_init_read_context(&pb_local, uncompressed_buffer, dlen);
+                tlen = dlen;
+                pbx = &pb_local.pub; // read from sync buffer
+            }
 #endif
             if (s && (s->debug & FF_FDEBUG_ID3V2)) {
                 int64_t pos = avio_tell(pbx);
-- 
2.52.0

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

Reply via email to