Skip to content

Commit a61dc88

Browse files
authored
Merge pull request #244 from sxci/etag_overflow
大数内存溢出 [ci skip]
2 parents 30b344b + e29e666 commit a61dc88

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

library/src/androidTest/java/com/qiniu/android/EtagTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.test.AndroidTestCase;
44

55
import com.qiniu.android.common.Constants;
6+
import com.qiniu.android.storage.Configuration;
67
import com.qiniu.android.utils.Etag;
78

89
import junit.framework.Assert;
@@ -40,6 +41,13 @@ public void testFile() throws IOException {
4041
f = TempFile.createFile(9 * 1024);
4142
Assert.assertEquals("ljgVjMtyMsOgIySv79U8Qz4TrUO4", Etag.file(f));
4243
TempFile.remove(f);
44+
}
4345

46+
public void testLongToInt() {
47+
long len = 2323435710l;
48+
int b = (int) ((len + Configuration.BLOCK_SIZE - 1) / Configuration.BLOCK_SIZE);
49+
Assert.assertEquals("不应该溢出", 554, b);
50+
int a = (int) (len + Configuration.BLOCK_SIZE - 1) / Configuration.BLOCK_SIZE;
51+
Assert.assertNotSame("预计会溢出", 554, a);
4452
}
4553
}

library/src/main/java/com/qiniu/android/utils/Etag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static String stream(InputStream in, long len) throws IOException {
8181
return "Fto5o-5ea0sNMlW_75VgGJCv2AcJ";
8282
}
8383
byte[] buffer = new byte[64 * 1024];
84-
byte[][] blocks = new byte[(int) (len + Configuration.BLOCK_SIZE - 1) / Configuration.BLOCK_SIZE][];
84+
byte[][] blocks = new byte[(int) ((len + Configuration.BLOCK_SIZE - 1) / Configuration.BLOCK_SIZE)][];
8585
for (int i = 0; i < blocks.length; i++) {
8686
long left = len - (long) Configuration.BLOCK_SIZE * i;
8787
long read = left > Configuration.BLOCK_SIZE ? Configuration.BLOCK_SIZE : left;

0 commit comments

Comments
 (0)