diff mbox series

[FFmpeg-devel] Fix bad ID3v2 tag length

Message ID CAAJ4pEy-y8bpc3LBYDEk0gr=Ononw2Nj+rdf=OLWcsk3tu1cVg@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] Fix bad ID3v2 tag length
Related show


Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

misc@atomas.com Jan. 9, 2020, 7:53 a.m. UTC
(this time with the attached git-format patch !)

The Id3v2 tag is set to a wrong size (14 bytes too large), when a CTOC
frame is included. It makes decoders believe the first MP3 frame is inside
the ID3v2 tag, and hence mungle the first mp3 frame.
The code source uses a hardcoded "16" magic value that is incorrect. (it
should be "2")

This patch fixes this bug *without* using magic values.


Thank you !
From 79e4fcd53e0bd322cc51b694af8a12adaa17efb4 Mon Sep 17 00:00:00 2001
From: Gilles Bouthenot <misc@atomas.com>
Date: Wed, 8 Jan 2020 19:47:55 +0100
Subject: [PATCH] Fix bad ID3v2 tag length

 libavformat/id3v2enc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series


diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
index ee0c4b28a1..5d821ea4db 100644
--- a/libavformat/id3v2enc.c
+++ b/libavformat/id3v2enc.c
@@ -268,15 +268,15 @@  static int write_ctoc(AVFormatContext *s, ID3v2EncContext *id3, int enc)
     if ((ret = avio_open_dyn_buf(&dyn_bc)) < 0)
         return ret;
-    id3->len += avio_put_str(dyn_bc, "toc");
+    avio_put_str(dyn_bc, "toc");
     avio_w8(dyn_bc, 0x03);
     avio_w8(dyn_bc, s->nb_chapters);
     for (int i = 0; i < s->nb_chapters; i++) {
         snprintf(name, 122, "ch%d", i);
-        id3->len += avio_put_str(dyn_bc, name);
+        avio_put_str(dyn_bc, name);
     len = avio_get_dyn_buf(dyn_bc, &dyn_buf);
-    id3->len += 16 + ID3v2_HEADER_SIZE;
+    id3->len += len + ID3v2_HEADER_SIZE;
     avio_wb32(s->pb, MKBETAG('C', 'T', 'O', 'C'));
     avio_wb32(s->pb, len);