Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ 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) {
if (!hasNonNullValue()) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}