From c2bcffb34ebe4399b523a44f69d23761648bd0c4 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Mon, 18 Jul 2016 11:42:56 -0700 Subject: [PATCH] HADOOP-13202. Avoid possible overflow in org.apache.hadoop.util.bloom.BloomFilter#getNBytes. Contributed by Kai Sasaki. --- .../org/apache/hadoop/util/bloom/BloomFilter.java | 2 +- .../apache/hadoop/util/bloom/TestBloomFilters.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java index f8b95192c8..82d18b8a99 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java @@ -234,6 +234,6 @@ public void readFields(DataInput in) throws IOException { /* @return number of bytes needed to hold bit vector */ private int getNBytes() { - return (vectorSize + 7) / 8; + return (int)(((long)vectorSize + 7) / 8); } }//end class diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java index 6ff854d1fb..85525659c9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java @@ -239,6 +239,18 @@ public void testFiltersWithMurmurHash() { 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);