diff --git a/parquet-column/src/main/java/org/apache/parquet/column/statistics/BinaryStatistics.java b/parquet-column/src/main/java/org/apache/parquet/column/statistics/BinaryStatistics.java index 87d39bf16e..9488a38494 100644 --- a/parquet-column/src/main/java/org/apache/parquet/column/statistics/BinaryStatistics.java +++ b/parquet-column/src/main/java/org/apache/parquet/column/statistics/BinaryStatistics.java @@ -105,7 +105,7 @@ String stringify(Binary value) { @Override public boolean isSmallerThan(long size) { - return !hasNonNullValue() || ((min.length() + max.length()) < size); + return !hasNonNullValue() || (((long) min.length() + max.length()) < size); } public boolean isSmallerThanWithTruncation(long size, int truncationLength) { @@ -113,8 +113,8 @@ public boolean isSmallerThanWithTruncation(long size, int truncationLength) { return true; } - int minTruncateLength = Math.min(min.length(), truncationLength); - int maxTruncateLength = Math.min(max.length(), truncationLength); + long minTruncateLength = Math.min(min.length(), truncationLength); + long maxTruncateLength = Math.min(max.length(), truncationLength); return minTruncateLength + maxTruncateLength < size; } diff --git a/parquet-column/src/test/java/org/apache/parquet/column/statistics/TestStatistics.java b/parquet-column/src/test/java/org/apache/parquet/column/statistics/TestStatistics.java index dec244f629..92eaa7a302 100644 --- a/parquet-column/src/test/java/org/apache/parquet/column/statistics/TestStatistics.java +++ b/parquet-column/src/test/java/org/apache/parquet/column/statistics/TestStatistics.java @@ -927,4 +927,15 @@ public void testNoopStatistics() { assertThrows(UnsupportedOperationException.class, stats::minAsString); assertThrows(UnsupportedOperationException.class, () -> stats.isSmallerThan(0)); } + + @Test + public void testBinaryIsSmallerThanNoOverflowForLargeValues() { + BinaryStatistics stats = new BinaryStatistics(); + // Create a Binary whose length() reports 2^30 without allocating 1 GB + Binary fakeLarge = Binary.fromConstantByteArray(new byte[0], 0, 1 << 30); + stats.updateStats(fakeLarge); + + // min.length() + max.length() = 2^31, must not overflow int to negative + assertFalse(stats.isSmallerThan(4096)); + } }