[MPlayer-cvslog] r34719 - in trunk: help/help_mp-en.h libmpdemux/demux_audio.c
reimar
subversion at mplayerhq.hu
Mon Feb 13 20:36:01 CET 2012
Author: reimar
Date: Mon Feb 13 20:36:01 2012
New Revision: 34719
Log:
Detect ID3v2 tag at the end of the file and stop demuxing before
its start.
Avoids trying to decode its data as MP3.
Patch by Benoît Thébaudeau [benoit thebaudeau {} advansee com].
Modified:
trunk/libmpdemux/demux_audio.c
Changes in other areas also in this revision:
Modified:
trunk/help/help_mp-en.h
Modified: trunk/libmpdemux/demux_audio.c
==============================================================================
--- trunk/libmpdemux/demux_audio.c Mon Feb 13 20:33:48 2012 (r34718)
+++ trunk/libmpdemux/demux_audio.c Mon Feb 13 20:36:01 2012 (r34719)
@@ -323,6 +323,34 @@ static unsigned int mp3_vbr_frames(strea
return 0;
}
+/**
+ * @brief Determine the total size of an ID3v2 tag.
+ *
+ * @param maj_ver major version of the ID3v2 tag
+ * @param s stream to be read, assumed to be positioned at revision byte
+ *
+ * @return 0 (error or malformed tag) or tag size
+ */
+static unsigned int id3v2_tag_size(uint8_t maj_ver, stream_t *s) {
+ unsigned int header_footer_size;
+ unsigned int size;
+ int i;
+
+ if(stream_read_char(s) == 0xff)
+ return 0;
+ header_footer_size = ((stream_read_char(s) & 0x10) && maj_ver >= 4) ? 20 : 10;
+
+ size = 0;
+ for(i = 0; i < 4; i++) {
+ uint8_t data = stream_read_char(s);
+ if (data & 0x80)
+ return 0;
+ size = size << 7 | data;
+ }
+
+ return header_footer_size + size;
+}
+
static int demux_audio_open(demuxer_t* demuxer) {
stream_t *s;
sh_audio_t* sh_audio;
@@ -356,12 +384,10 @@ static int demux_audio_open(demuxer_t* d
// We found wav header. Now we can have 'fmt ' or a mp3 header
// empty the buffer
step = 4;
- } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && (hdr[3] >= 2)) {
- int len;
- stream_skip(s,2);
- stream_read(s,hdr,4);
- len = (hdr[0]<<21) | (hdr[1]<<14) | (hdr[2]<<7) | hdr[3];
- stream_skip(s,len);
+ } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && hdr[3] >= 2 && hdr[3] != 0xff) {
+ unsigned int len = id3v2_tag_size(hdr[3], s);
+ if(len > 0)
+ stream_skip(s,len-10);
step = 4;
} else if( found_WAVE && hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) {
frmt = WAV;
@@ -444,6 +470,25 @@ static int demux_audio_open(demuxer_t* d
g = stream_read_char(s);
demux_info_add(demuxer,"Genre",genres[g]);
}
+ stream_seek(s,demuxer->movi_end-10);
+ stream_read(s,hdr,4);
+ if(!memcmp(hdr,"3DI",3) && hdr[3] >= 4 && hdr[3] != 0xff) {
+ unsigned int len = id3v2_tag_size(hdr[3], s);
+ if(len > 0) {
+ if(len > demuxer->movi_end - demuxer->movi_start) {
+ mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MPDEMUX_AUDIO_BadID3v2TagSize,len);
+ len = FFMIN(10,demuxer->movi_end-demuxer->movi_start);
+ } else {
+ stream_seek(s,demuxer->movi_end-len);
+ stream_read(s,hdr,4);
+ if(memcmp(hdr,"ID3",3) || hdr[3] < 4 || hdr[3] == 0xff || id3v2_tag_size(hdr[3], s) != len) {
+ mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MPDEMUX_AUDIO_DamagedAppendedID3v2Tag);
+ len = FFMIN(10,demuxer->movi_end-demuxer->movi_start);
+ }
+ }
+ demuxer->movi_end -= len;
+ }
+ }
}
if (duration && demuxer->movi_end && demuxer->movi_end > demuxer->movi_start) sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / duration;
sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec;
More information about the MPlayer-cvslog
mailing list