[xiph-commits] r17534 - trunk/Tremor
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Wed Oct 13 23:33:23 PDT 2010
Author: xiphmont
Date: 2010-10-13 23:33:23 -0700 (Wed, 13 Oct 2010)
New Revision: 17534
Modified:
trunk/Tremor/vorbisfile.c
Log:
Commit provisional fix for 64 bit math overflow in libvorbisfile
seeking bisection computation
This is the equivalent of the r15921 fix in reference, but doesn't
require a double cast (for obvious reasons). The technique is
different, the intent is the same (avoid a 64x64= >64 bit overflow)
Modified: trunk/Tremor/vorbisfile.c
===================================================================
--- trunk/Tremor/vorbisfile.c 2010-10-14 04:25:03 UTC (rev 17533)
+++ trunk/Tremor/vorbisfile.c 2010-10-14 06:33:23 UTC (rev 17534)
@@ -1352,6 +1352,36 @@
return OV_EBADLINK;
}
+/* rescales the number x from the range of [0,from] to [0,to]
+ x is in the range [0,from]
+ from, to are in the range [1, 1<<62-1] */
+ogg_int64_t rescale64(ogg_int64_t x, ogg_int64_t from, ogg_int64_t to){
+ ogg_int64_t frac=0;
+ ogg_int64_t ret=0;
+ int i;
+ if(x >= from) return to;
+ if(x <= 0) return 0;
+
+ for(i=0;i<64;i++){
+ if(x>=from){
+ frac|=1;
+ x-=from;
+ }
+ x<<=1;
+ frac<<=1;
+ }
+
+ for(i=0;i<64;i++){
+ if(frac & 1){
+ ret+=to;
+ }
+ frac>>=1;
+ ret>>=1;
+ }
+
+ return ret;
+}
+
/* Page granularity seek (faster than sample granularity because we
don't do the last bit of decode to find a specific sample).
@@ -1397,8 +1427,9 @@
bisect=begin;
}else{
/* take a (pretty decent) guess. */
- bisect=begin +
- (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
+ bisect=begin + rescale64(target-begintime,
+ endtime-begintime,
+ end-begin) - CHUNKSIZE;
if(bisect<begin+CHUNKSIZE)
bisect=begin;
}
More information about the commits
mailing list