Follow up to PR 1606 to avoid int overflow during star tree creation.
When computing offsets that are larger than Integer.MAX_VALUE (as a
result of multiplication), we need to ensure that the result of
multiplication does not cause integer overflow, and is properly upcasted
to long.
@@ -206,9 +206,10 @@ public class StarTreeDataSorter {
byte[] dimBuff = new byte[dimensionSizeInBytes];
byte[] metBuff = new byte[metricSizeInBytes];
- copyTo(startOffset + (pointer * totalSizeInBytes), dimBuff, 0, dimensionSizeInBytes);
+ long pointerOffset = (long) pointer * totalSizeInBytes;
+ copyTo(startOffset + pointerOffset, dimBuff, 0, dimensionSizeInBytes);
if (metricSizeInBytes > 0) {
- copyTo(startOffset + (pointer * totalSizeInBytes) + dimensionSizeInBytes, metBuff, 0, metricSizeInBytes);
+ copyTo(startOffset + pointerOffset + dimensionSizeInBytes, metBuff, 0, metricSizeInBytes);
}
pointer = pointer + 1;
