This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-java.git
The following commit(s) were added to refs/heads/master by this push:
new 689547cc9 GH-3449: Fix BinaryStats int overflow (#3448)
689547cc9 is described below
commit 689547cc9f5575b565b60f0b4ba523528d0e4b42
Author: Jiayi-Wang-db <[email protected]>
AuthorDate: Wed Mar 18 02:56:09 2026 +0100
GH-3449: Fix BinaryStats int overflow (#3448)
---
.../apache/parquet/column/statistics/BinaryStatistics.java | 6 +++---
.../org/apache/parquet/column/statistics/TestStatistics.java | 11 +++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
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 87d39bf16..9488a3849 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 @@ public class BinaryStatistics extends Statistics<Binary> {
@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 class BinaryStatistics extends Statistics<Binary> {
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 dec244f62..92eaa7a30 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 class TestStatistics {
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));
+ }
}