diff -ur mythmusic-0.16/mythmusic/maddecoder.cpp mythmusic-0.16-r1/mythmusic/maddecoder.cpp --- mythmusic-0.16/mythmusic/maddecoder.cpp 2004-05-29 07:44:39.000000000 +0200 +++ mythmusic-0.16-r1/mythmusic/maddecoder.cpp 2004-11-13 21:11:37.626952288 +0100 @@ -19,6 +19,7 @@ #include #define XING_MAGIC (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g') +#define ID3V2_MAGIC (('I' << 24) | ('D' << 16) | ('3' << 8) | 2) MadDecoder::MadDecoder(const QString &file, DecoderFactory *d, QIODevice *i, Output *o) @@ -147,6 +148,46 @@ output_size = 0; } +unsigned long MadDecoder::skipNonUnsynchronizedTag(unsigned char* buffer) +{ + unsigned long offset = 0; + unsigned int magic = ((*buffer << 24) | (*(buffer+1) << 16) | (*(buffer + 2) << 8) | *(buffer+3)); + + if(header != ID3V2_MAGIC) // Not ID3v2 + goto fail; + buffer += 4; + if(*buffer != 0x0) // Not v2.2.0 + goto fail; + buffer ++; + if(*buffer & 0xbf != 0x0) // Either tag is unsynchronized or flags byte contains garbage (tbt) + goto fail; + + // building offset concatenating the 7 first bits of the 4 next bytes + // if any byte has its 8th bit set, that's an error + buffer++; + if(*buffer > 0x7f) + goto fail; + offset |= *buffer << 21; + buffer++; + if(*buffer > 0x7f) + goto fail; + offset |= *buffer << 14; + buffer++; + if(*buffer > 0x7f) + goto fail; + offset |= *buffer << 7; + buffer++; + if(*buffer > 0x7f) + goto fail; + offset |= *buffer; + offset += 10; // Tag header is not in length + + return offset; + + fail: + return 0; +} + bool MadDecoder::findXingHeader(struct mad_bitptr ptr, unsigned int bitlen) { if (bitlen < 64 || mad_bit_read(&ptr, 32) != XING_MAGIC) @@ -205,6 +246,7 @@ { bool result = false; int count = 0; + bool firstPass = true; while (1) { if (input_bytes < globalBufferSize) { @@ -220,6 +262,12 @@ mad_stream_buffer(&stream, (unsigned char *) input_buf, input_bytes); + if(firstPass) + { + stream.skiplen = skipNotUnsynchronizedTag((unsigned char *)input_buf); + firstPass = false; + } + bool done = false; while (! done) { if (mad_frame_decode(&frame, &stream) != -1) diff -ur mythmusic-0.16/mythmusic/maddecoder.h mythmusic-0.16-r1/mythmusic/maddecoder.h --- mythmusic-0.16/mythmusic/maddecoder.h 2003-05-04 02:18:16.000000000 +0200 +++ mythmusic-0.16-r1/mythmusic/maddecoder.h 2004-11-13 21:07:33.572054272 +0100 @@ -36,6 +36,7 @@ void flush(bool = FALSE); void deinit(); bool findHeader(); + unsigned long skipNonUnsynchronizedTag(unsigned char*); bool findXingHeader(struct mad_bitptr, unsigned int); void calcLength(struct mad_header *);