Fixed a division by zero in mp3 metadata parser.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11003 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-09-19 18:27:43 +00:00
parent f5520f5cef
commit 7f1346d641

View file

@ -1000,7 +1000,11 @@ static int getsonglength(int fd, struct mp3entry *entry)
if(filetime == 0)
{
filetime = (entry->filesize - bytecount) / (info.bitrate / 8);
/* Prevent a division by zero */
if (info.bitrate < 8)
filetime = 0;
else
filetime = (entry->filesize - bytecount) / (info.bitrate / 8);
/* bitrate is in kbps so this delivers milliseconds. Doing bitrate / 8
* instead of filesize * 8 is exact, because mpeg audio bitrates are
* always multiples of 8, and it avoids overflows. */