Author: nextgens
Date: 2007-03-15 17:08:31 +0000 (Thu, 15 Mar 2007)
New Revision: 12120

Modified:
   trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
   trunk/freenet/src/freenet/support/io/FileBucket.java
   trunk/freenet/src/freenet/support/io/RandomAccessFileBucket.java
Log:
When we cast the result of an int. multiplication into a long, we have to 
handle the overflow

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2007-03-15 17:05:15 UTC (rev 12119)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2007-03-15 17:08:31 UTC (rev 12120)
@@ -82,7 +82,7 @@
                        if(splitfileDataBlocks[i] == null) throw new 
MetadataParseException("Null: data block "+i+" of "+splitfileDataBlocks.length);
                for(int i=0;i<splitfileCheckBlocks.length;i++)
                        if(splitfileCheckBlocks[i] == null) throw new 
MetadataParseException("Null: check block "+i+" of 
"+splitfileCheckBlocks.length);
-               long finalLength = splitfileDataBlocks.length * 
CHKBlock.DATA_LENGTH;
+               long finalLength = splitfileDataBlocks.length * 
CHKBlock.DATA_LENGTH * 1L;
                if(finalLength > overrideLength) {
                        if(finalLength - overrideLength > CHKBlock.DATA_LENGTH)
                                throw new 
FetchException(FetchException.INVALID_METADATA, "Splitfile is "+finalLength+" 
but length is "+finalLength);

Modified: trunk/freenet/src/freenet/support/io/FileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileBucket.java        2007-03-15 
17:05:15 UTC (rev 12119)
+++ trunk/freenet/src/freenet/support/io/FileBucket.java        2007-03-15 
17:08:31 UTC (rev 12120)
@@ -319,8 +319,8 @@
                if(length % splitSize > 0) bucketCount++;
                Bucket[] buckets = new Bucket[bucketCount];
                for(int i=0;i<buckets.length;i++) {
-                       long startAt = i * splitSize;
-                       long endAt = Math.min((i+1) * splitSize, length);
+                       long startAt = i * splitSize * 1L;
+                       long endAt = Math.min(startAt + splitSize * 1L, length);
                        long len = endAt - startAt;
                        buckets[i] = new ReadOnlyFileSliceBucket(file, startAt, 
len);
                }

Modified: trunk/freenet/src/freenet/support/io/RandomAccessFileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/RandomAccessFileBucket.java    
2007-03-15 17:05:15 UTC (rev 12119)
+++ trunk/freenet/src/freenet/support/io/RandomAccessFileBucket.java    
2007-03-15 17:08:31 UTC (rev 12120)
@@ -205,10 +205,10 @@
         Bucket[] ret = new Bucket[blocks];

         for (int i = 0; i < blocks; i++) {
-            final long localOffset = i * blockSize + offset;
+            final long localOffset = i * blockSize * 1L + offset;
             int blockLen = blockSize;
             if (i == nBlocks - 1) {
-                blockLen = (int) (length - (nBlocks - 1) * blockSize);
+                blockLen = (int) (length - (nBlocks - 1) * blockSize * 1L);
             }
             ret[i] = new RandomAccessFileBucket(file, localOffset, blockLen, 
readOnly);
         }


Reply via email to