From 6d16ad64c842fbe1e49343b6d5b9cecba5dd9ab1 Mon Sep 17 00:00:00 2001 From: Buschel Date: Mon, 20 Apr 2009 19:10:27 +0000 Subject: [PATCH] Fix FS#10139 (broken seek for very long mp3 files) through avoiding int32 overflow in calculation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20755 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/mpa.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 1b71bde79..d5b4d0288 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -91,12 +91,17 @@ static int get_file_pos(int newtime) struct mp3entry *id3 = ci->id3; if (id3->vbr) { + /* Convert newtime and id3->length to seconds to + * avoid overflow */ + unsigned int newtime_s = newtime/1000; + unsigned int length_s = id3->length/1000; + if (id3->has_toc) { /* Use the TOC to find the new position */ unsigned int percent, remainder; int curtoc, nexttoc, plen; - percent = (newtime*100) / id3->length; + percent = (newtime_s*100) / length_s; if (percent > 99) percent = 99; @@ -111,14 +116,13 @@ static int get_file_pos(int newtime) pos = (id3->filesize/256)*curtoc; /* Use the remainder to get a more accurate position */ - remainder = (newtime*100) % id3->length; - remainder = (remainder*100) / id3->length; + remainder = (newtime_s*100) % length_s; + remainder = (remainder*100) / length_s; plen = (nexttoc - curtoc)*(id3->filesize/256); pos += (plen/100)*remainder; } else { /* No TOC exists, estimate the new position */ - pos = (id3->filesize / (id3->length / 1000)) * - (newtime / 1000); + pos = (id3->filesize / length_s) * newtime_s; } } else if (id3->bitrate) { pos = newtime * (id3->bitrate / 8); -- 2.11.4.GIT