Author: toad
Date: 2005-11-09 22:32:26 +0000 (Wed, 09 Nov 2005)
New Revision: 7507
Modified:
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/support/BucketTools.java
trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
trunk/freenet/src/freenet/support/io/SpyInputStream.java
Log:
149:
Fixed some more bugs.
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2005-11-09 21:59:52 UTC (rev
7506)
+++ trunk/freenet/src/freenet/node/Version.java 2005-11-09 22:32:26 UTC (rev
7507)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 148;
+ public static final int buildNumber = 149;
/** Oldest build of Fred we will talk to */
public static final int lastGoodBuild = 144;
Modified: trunk/freenet/src/freenet/support/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/BucketTools.java 2005-11-09 21:59:52 UTC
(rev 7506)
+++ trunk/freenet/src/freenet/support/BucketTools.java 2005-11-09 22:32:26 UTC
(rev 7507)
@@ -348,14 +348,25 @@
* @throws IOException If there was an error reading from the bucket or
writing to the stream. */
public static void copyTo(Bucket decodedData, OutputStream os, long
truncateLength) throws IOException {
if(truncateLength == 0) return;
+ if(truncateLength < 0) truncateLength = Long.MAX_VALUE;
InputStream is = decodedData.getInputStream();
byte[] buf = new byte[4096];
long moved = 0;
while(moved < truncateLength) {
- int bytes = Math.min(buf.length, (int)(truncateLength -
moved));
- is.read(buf, 0, bytes);
+ // DO NOT move the (int) inside the Math.min()! big
numbers truncate to negative numbers.
+ int bytes = (int) Math.min(buf.length, truncateLength -
moved);
+ if(bytes <= 0)
+ throw new
IllegalStateException("bytes="+bytes+", truncateLength="+truncateLength+",
moved="+moved);
+ bytes = is.read(buf, 0, bytes);
+ if(bytes <= 0) {
+ if(truncateLength == Long.MAX_VALUE)
+ break;
+ throw new IOException("Could not move required
quantity of data: "+bytes);
+ }
os.write(buf, 0, bytes);
+ moved += bytes;
}
+ is.close();
}
/**
Modified:
trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2005-11-09 21:59:52 UTC (rev 7506)
+++ trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2005-11-09 22:32:26 UTC (rev 7507)
@@ -145,15 +145,20 @@
}
public final int available() {
- return (int) (dataLength - ptr);
+ int x = (int)(dataLength - ptr);
+ return (x < 0) ? 0 : x;
}
public int read(byte[] buf, int offset, int length) throws
IOException {
- if(ptr > dataLength) return -1;
- length = Math.min(length, available());
+ // FIXME remove debugging
+ if(length+offset > buf.length || offset < 0 || length <
0)
+ throw new
ArrayIndexOutOfBoundsException("a="+offset+", b="+length+", length
"+buf.length);
+ int x = available();
+ if(x <= 0) return -1;
+ length = Math.min(length, x);
int readBytes = in.read(buf, offset, length);
if(readBytes <= 0) return readBytes;
- ptr += dataLength;
+ ptr += readBytes;
pcfb.blockDecipher(buf, offset, readBytes);
return readBytes;
}
Modified: trunk/freenet/src/freenet/support/io/SpyInputStream.java
===================================================================
--- trunk/freenet/src/freenet/support/io/SpyInputStream.java 2005-11-09
21:59:52 UTC (rev 7506)
+++ trunk/freenet/src/freenet/support/io/SpyInputStream.java 2005-11-09
22:32:26 UTC (rev 7507)
@@ -87,6 +87,9 @@
synchronized (tfb) {
println(".read(byte[], int, int)");
checkValid();
+ // FIXME remove debugging
+ if(a+b > bytes.length || a < 0 || b < 0)
+ throw new
ArrayIndexOutOfBoundsException("a="+a+", b="+b+", length "+bytes.length);
return in.read(bytes, a, b);
}
}