Skip to content

Commit d60496e

Browse files
authored
BytesWritable causes OOME when array size reaches Integer.MAX_VALUE. (#393)
1 parent b214bbd commit d60496e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
@InterfaceStability.Stable
3939
public class BytesWritable extends BinaryComparable
4040
implements WritableComparable<BinaryComparable> {
41+
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
4142
private static final int LENGTH_BYTES = 4;
4243

4344
private static final byte[] EMPTY_BYTES = new byte[0];
@@ -126,7 +127,7 @@ public int getSize() {
126127
public void setSize(int size) {
127128
if (size > getCapacity()) {
128129
// Avoid overflowing the int too early by casting to a long.
129-
long newSize = Math.min(Integer.MAX_VALUE, (3L * size) / 2L);
130+
long newSize = Math.min(MAX_ARRAY_SIZE, (3L * size) / 2L);
130131
setCapacity((int) newSize);
131132
}
132133
this.size = size;

0 commit comments

Comments
 (0)