diff mbox series

[FFmpeg-devel] libavformat/id3v2: Read full null seperated list for text info frames

Message ID 1118083116.39618.1617751350909@office.mailbox.org
State New
Headers show
Series [FFmpeg-devel] libavformat/id3v2: Read full null seperated list for text info frames | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lode Willems April 6, 2021, 11:22 p.m. UTC
All id3v2.4 text information frames are null separated lists:
https://id3.org/id3v2.4.0-frames

This change reads all values into the metadata dictionary without changing the
outputs of ffmpeg or ffprobe

Relevant ticket: https://trac.ffmpeg.org/ticket/6949

Signed-off-by: Lode Willems <me@lodewillems.com>
---
 libavformat/id3v2.c    | 5 ++++-
 libavformat/metadata.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Lode Willems July 20, 2021, 12:14 a.m. UTC | #1
Could someone please review this patch?

On 7/04/2021 01:22, Lode Willems wrote:
> All id3v2.4 text information frames are null separated lists:
> https://id3.org/id3v2.4.0-frames
> 
> This change reads all values into the metadata dictionary without changing the
> outputs of ffmpeg or ffprobe
> 
> Relevant ticket: https://trac.ffmpeg.org/ticket/6949
> 
> Signed-off-by: Lode Willems <me@lodewillems.com>
> ---
>   libavformat/id3v2.c    | 5 ++++-
>   libavformat/metadata.c | 2 +-
>   2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
> index 863709abbf..9ef56a52c2 100644
> --- a/libavformat/id3v2.c
> +++ b/libavformat/id3v2.c
> @@ -320,7 +320,7 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
>                         AVDictionary **metadata, const char *key)
>   {
>       uint8_t *dst;
> -    int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL;
> +    int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL | AV_DICT_MULTIKEY;
>       unsigned genre;
>   
>       if (taglen < 1)
> @@ -329,6 +329,8 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
>       encoding = avio_r8(pb);
>       taglen--; /* account for encoding type byte */
>   
> +    /* Read all null-terminated values */
> +    while (taglen > 0) {
>       if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
>           av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
>           return;
> @@ -353,6 +355,7 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
>   
>       if (dst)
>           av_dict_set(metadata, key, dst, dict_flags);
> +    }
>   }
>   
>   static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
> diff --git a/libavformat/metadata.c b/libavformat/metadata.c
> index b9b6de7972..68382e7937 100644
> --- a/libavformat/metadata.c
> +++ b/libavformat/metadata.c
> @@ -50,7 +50,7 @@ void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
>                       key = dc->native;
>                       break;
>                   }
> -        av_dict_set(&dst, key, mtag->value, 0);
> +        av_dict_set(&dst, key, mtag->value, AV_DICT_DONT_OVERWRITE);
>       }
>       av_dict_free(pm);
>       *pm = dst;
>
diff mbox series

Patch

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 863709abbf..9ef56a52c2 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -320,7 +320,7 @@  static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
                       AVDictionary **metadata, const char *key)
 {
     uint8_t *dst;
-    int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL;
+    int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL | AV_DICT_MULTIKEY;
     unsigned genre;
 
     if (taglen < 1)
@@ -329,6 +329,8 @@  static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
     encoding = avio_r8(pb);
     taglen--; /* account for encoding type byte */
 
+    /* Read all null-terminated values */
+    while (taglen > 0) {
     if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
         av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
         return;
@@ -353,6 +355,7 @@  static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen,
 
     if (dst)
         av_dict_set(metadata, key, dst, dict_flags);
+    }
 }
 
 static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index b9b6de7972..68382e7937 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -50,7 +50,7 @@  void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
                     key = dc->native;
                     break;
                 }
-        av_dict_set(&dst, key, mtag->value, 0);
+        av_dict_set(&dst, key, mtag->value, AV_DICT_DONT_OVERWRITE);
     }
     av_dict_free(pm);
     *pm = dst;