From: toots via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: toots <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] libavformat/id3v2.c: fix lyrics parsing implementation. (PR #21199)
Date: Sun, 14 Dec 2025 19:35:59 -0000
Message-ID: <176574095997.60.16398685080281332212@2cb04c0e5124> (raw)
PR #21199 opened by toots
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21199
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21199.patch
>From 797801d40d819b0cd765ba6d0c327e497181848f Mon Sep 17 00:00:00 2001
From: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sun, 14 Dec 2025 13:34:48 -0600
Subject: [PATCH] libavformat/id3v2.c: fix lyrics parsing implementation.
---
libavformat/id3v2.c | 59 ++++++++++++++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 17 deletions(-)
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 9d4a9802a9..0eb40a2a7b 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -371,9 +371,9 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
AVDictionary **metadata)
{
- uint8_t lang[4];
+ char lang[4];
uint8_t *descriptor = NULL; // 'Content descriptor'
- uint8_t *text;
+ uint8_t *text = NULL;
char *key;
int encoding;
int ok = 0;
@@ -389,29 +389,54 @@ static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
lang[3] = '\0';
taglen -= 3;
- if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0 || taglen < 0)
- goto error;
-
- if (decode_str(s, pb, encoding, &text, &taglen) < 0 || taglen < 0)
- goto error;
-
- // FFmpeg does not support hierarchical metadata, so concatenate the keys.
- key = av_asprintf("lyrics-%s%s%s", descriptor[0] ? (char *)descriptor : "",
- descriptor[0] ? "-" : "",
- lang);
- if (!key) {
- av_free(text);
- goto error;
+ // Empty descriptor can be one or two
+ // \000 characters depending on the implementation's
+ // choice. We can consume all \000 charaters. If that
+ // consumes all the remaining one, text is also empty
+ // which is correct.
+ if (!*pb->buf_ptr) {
+ while (taglen > 0 && !*pb->buf_ptr) {
+ avio_r8(pb);
+ taglen--;
+ }
+ descriptor = av_strdup("");
+ if (!descriptor)
+ goto error;
+ } else {
+ if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0 || taglen < 0)
+ goto error;
+ // String should be null-terminated and followed by a \000 text separator.
+ if (taglen <= 0 || *pb->buf_ptr)
+ goto error;
+ avio_r8(pb);
+ taglen--;
}
- av_dict_set(metadata, key, text,
- AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+ if (!taglen || !*pb->buf_ptr) {
+ text = av_strdup("");
+ if (!text)
+ goto error;
+ } else {
+ if (decode_str(s, pb, encoding, &text, &taglen) < 0 || taglen < 0)
+ goto error;
+ }
+
+ // FFmpeg does not support hierarchical metadata, so concatenate the keys.
+ key = av_asprintf("lyrics%s%s%s%s", descriptor[0] || strlen(lang) == 3 ? "-" : "",
+ descriptor[0] ? (char *)descriptor : "",
+ descriptor[0] ? "-" : "",
+ strlen(lang) == 3 ? lang : "");
+ if (!key)
+ goto error;
+
+ av_dict_set(metadata, key, text, AV_DICT_DONT_STRDUP_KEY);
ok = 1;
error:
if (!ok)
av_log(s, AV_LOG_ERROR, "Error reading lyrics, skipped\n");
av_free(descriptor);
+ av_free(text);
}
/**
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-12-14 19:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=176574095997.60.16398685080281332212@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/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