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

This commit is contained in:
Haohui Mai 2015-11-19 12:54:08 -08:00
parent 866dce4e8e
commit 747455a13b
2 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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;
}