Ensure ORC StringStatistics sum does not overflow
@@ -20,6 +20,7 @@ import java.util.Optional;
import static com.facebook.presto.orc.metadata.statistics.StringStatistics.STRING_VALUE_BYTES_OVERHEAD;
import static com.google.common.base.Verify.verify;
+import static java.lang.Math.addExact;
import static java.util.Objects.requireNonNull;
public class StringStatisticsBuilder
@@ -41,7 +42,7 @@ public class StringStatisticsBuilder
requireNonNull(value, "value is null");
nonNullValueCount++;
- sum += value.length();
+ sum = addExact(sum, value.length());
updateMinMax(value);
}
@@ -66,7 +67,7 @@ public class StringStatisticsBuilder
requireNonNull(value.getMax(), "value.getMax() is null");
nonNullValueCount += valueCount;
- sum += value.getSum();
+ sum = addExact(sum, value.getSum());
updateMinMax(value.getMin());
updateMinMax(value.getMax());
}
