HADOOP-13202. Avoid possible overflow in org.apache.hadoop.util.bloom.BloomFilter#getNBytes. Contributed by Kai Sasaki.

(cherry picked from commit c2bcffb34e)
This commit is contained in:
Akira Ajisaka 2016-07-18 11:42:56 -07:00
parent 18a7623bc7
commit 09375baad1
2 changed files with 13 additions and 1 deletions

View File

@ -234,6 +234,6 @@ public class BloomFilter extends Filter {
/* @return number of bytes needed to hold bit vector */
private int getNBytes() {
return (vectorSize + 7) / 8;
return (int)(((long)vectorSize + 7) / 8);
}
}//end class

View File

@ -239,6 +239,18 @@ public class TestBloomFilters {
BloomFilterTestStrategy.FILTER_XOR_STRATEGY)).test();
}
@Test
public void testFiltersWithLargeVectorSize() {
int hashId = Hash.MURMUR_HASH;
Filter filter
= new BloomFilter(Integer.MAX_VALUE, hashFunctionNumber, hashId);
BloomFilterCommonTester.of(hashId, numInsertions)
.withFilterInstance(filter)
.withTestCases(ImmutableSet.of(
BloomFilterTestStrategy.WRITE_READ_STRATEGY
)).test();
}
@Test
public void testNot() {
BloomFilter bf = new BloomFilter(8, 1, Hash.JENKINS_HASH);