These are a few samples of mp3 files that have their id3v1 tag inside the last frame. This cause decoding of an invalid last frame for the mp3. A patch has been submitted to fix this for non seekable streams: --- mp3.c (revision 15776) +++ mp3.c (working copy) @@ -159,6 +159,10 @@ [125] = "Dance Hall", }; +typedef struct MPAContext { + int found_id3v1; +} MPAContext; + /* buf must be ID3v2_HEADER_SIZE byte long */ static int id3v2_match(const uint8_t *buf) { @@ -358,6 +362,7 @@ genre = buf[127]; if (genre <= ID3v1_GENRE_MAX) av_strlcpy(s->genre, id3v1_genre_str[genre], sizeof(s->genre)); + ((MPAContext*)s->priv_data)->found_id3v1 = 1; return 0; } @@ -505,10 +510,20 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size; + int64_t size_left; // AVStream *st = s->streams[0]; size= MP3_PACKET_SIZE; + /* if we're nearing the end of the input and there's an + ID3v1 tag then make sure we don't read it as a packet */ + if (((MPAContext*)s->priv_data)->found_id3v1 && s->file_size && + (size_left = s->file_size - url_ftell(s->pb) - ID3v1_TAG_SIZE) < size) { + size = size_left; + if (size <= 0) + return AVERROR(EIO); + } + ret= av_get_packet(s->pb, pkt, size); pkt->stream_index = 0; @@ -645,7 +660,7 @@ AVInputFormat mp3_demuxer = { "mp3", NULL_IF_CONFIG_SMALL("MPEG audio"), - 0, + sizeof(MPAContext), mp3_read_probe, mp3_read_header, mp3_read_packet,