Browse Source

HADOOP-11901. BytesWritable fails to support 2G chunks due to integer overflow. Contributed by Reynold Xin.

Haohui Mai 9 years ago
parent
commit
747455a13b

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -1426,6 +1426,9 @@ Release 2.8.0 - UNRELEASED
     HADOOP-12484. Single File Rename Throws Incorrectly In Potential Race
     Condition Scenarios. (Gaurav Kanade via cnauroth)
 
+    HADOOP-11901. BytesWritable fails to support 2G chunks due to integer
+    overflow. (Reynold Xin via wheat9)
+
 Release 2.7.3 - UNRELEASED
 
   INCOMPATIBLE CHANGES

+ 3 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/BytesWritable.java

@@ -120,7 +120,9 @@ public class BytesWritable extends BinaryComparable
    */
   public void setSize(int size) {
     if (size > getCapacity()) {
-      setCapacity(size * 3 / 2);
+      // Avoid overflowing the int too early by casting to a long.
+      long newSize = Math.min(Integer.MAX_VALUE, (3L * size) / 2L);
+      setCapacity((int) newSize);
     }
     this.size = size;
   }