ffmpeg | branch: master | wm4 <nfx...@googlemail.com> | Fri Apr 24 12:26:39 
2015 +0200| [537ab680534e53bd298ba3f62d4aabb56afcd403] | committer: Michael 
Niedermayer

avformat/mp3: large id3 tags break concatenated file detection

If the file size is much larger than what is indicated in the XING
header, the demuxer assumes it's a concatenated file, and throws away
the (presumably) incorrect duration information. Unfortunately, this
also triggers if the id3 tags are very large (embedded pictures and
such). Then the half-baked heuristic not only breaks the duration
display, but also gapless audio.

Fix it by subtracting the size of the headers (the check is off by some
bytes, but that doesn't matter at all). Note that there could be an
arbitrary amount of tags _after_ the mp3 data, but hopefully these are
not too large to trigger the heuristic in practice.

Also add a warning when this happens.

Signed-off-by: Michael Niedermayer <michae...@gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=537ab680534e53bd298ba3f62d4aabb56afcd403
---

 libavformat/mp3dec.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 8c17776..abd7fc0 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -147,6 +147,7 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream 
*st,
     MP3DecContext *mp3 = s->priv_data;
     static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
     uint64_t fsize = avio_size(s->pb);
+    fsize = fsize >= avio_tell(s->pb) ? fsize - avio_tell(s->pb) : 0;
 
     /* Check for Xing / Info tag */
     avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
@@ -166,6 +167,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream 
*st,
         delta = FFMAX(fsize, mp3->header_filesize) - min;
         if (fsize > mp3->header_filesize && delta > min >> 4) {
             mp3->frames = 0;
+            av_log(s, AV_LOG_WARNING,
+                   "invalid concatenated file detected - using bitrate for 
duration\n");
         } else if (delta > min >> 4) {
             av_log(s, AV_LOG_WARNING,
                    "filesize and duration do not match (growing file?)\n");

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

Reply via email to