From e8b1787296dae2a69893bd0fe97b2361fb6180ba Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Sun, 8 Jan 2006 08:58:58 +0000 Subject: Discard some LAME header fields if the file length has changed since the header was written. Fixes some NPR podcasts. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8307 a1c6a512-1295-4272-9138-f99709370657 --- firmware/id3.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'firmware/id3.c') diff --git a/firmware/id3.c b/firmware/id3.c index 89864a659b..a2b6521b67 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -882,6 +882,32 @@ static int getsonglength(int fd, struct mp3entry *entry) bytecount += entry->id3v2len; + /* Validate byte count, in case the file has been edited without + * updating the header. + */ + if (info.byte_count) + { + const unsigned long expected = entry->filesize - entry->id3v1len + - entry->id3v2len; + const unsigned long diff = MAX(10240, info.byte_count / 20); + + if ((info.byte_count > expected + diff) + || (info.byte_count < expected - diff)) + { + DEBUGF("Note: info.byte_count differs from expected value by " + "%d bytes\n", labs((long) (expected - info.byte_count))); + info.byte_count = 0; + info.frame_count = 0; + info.file_time = 0; + info.enc_padding = 0; + + /* Even if the bitrate was based on "known bad" values, it + * should still be better for VBR files than using the bitrate + * of the first audio frame. + */ + } + } + entry->bitrate = info.bitrate; entry->frequency = info.frequency; entry->version = info.version; -- cgit v1.2.3