Bug in ByteBufferHashTable.java
In the method "reset()" of ByteBufferHashTable.java
maxBuckets = Math.min(tableArenaSize / bucketSizeWithHash, initialBuckets);
regrowthThreshold = maxSizeForBuckets(maxBuckets);
if (maxBuckets < 1) {
throw new IAE(
"Not enough capacity for even one row! Need[%,d] but have[%,d].",
bucketSizeWithHash + Ints.BYTES,
buffer.capacity()
);
}
// Start table part-way through the buffer so the last growth can start from zero and thereby use more space.
tableStart = tableArenaSize - maxBuckets * bucketSizeWithHash;
int nextBuckets = maxBuckets * 2;
while (true) {
final int nextTableStart = tableStart - nextBuckets * bucketSizeWithHash;
if (nextTableStart > tableArenaSize / 2) {
tableStart = nextTableStart;
nextBuckets = nextBuckets * 2;
} else {
break;
}
}
When tableArenaSize/bucketSizeWithHash is less than initialBuckets, maxBuckets will be tableArenaSize/bucketSizeWithHash.
Then, tableStart will be 0 for
tableStart = tableArenaSize - maxBuckets * bucketSizeWithHash;
The bug is If the value of nextBuckets * bucketSizeWithHash is out of Integer's range, the value nextTableStart will be wrong. The result of condition nextTableStart > tableArenaSize / 2 will be wrong.
So, I think the value of nextBuckets * bucketSizeWithHash should be long, and we should
make sure it is less than the maximum integer value.
Thanks @zhangxinyu1, do you want to make a pull-request to fix this?
@leventov Yes, could you please review this pull-request