LuciferYang commented on code in PR #56655:
URL: https://github.com/apache/spark/pull/56655#discussion_r3452655928
##########
common/utils-java/src/main/java/org/apache/spark/network/util/ByteUnit.java:
##########
@@ -54,6 +54,10 @@ public long toBytes(long d) {
if (d < 0) {
throw new IllegalArgumentException("Negative size value. Size must be
positive: " + d);
}
+ if (Long.MAX_VALUE / multiplier < d) {
+ throw new IllegalArgumentException("Conversion of " + d + " " + name()
+ + " to bytes exceeds Long.MAX_VALUE");
Review Comment:
Done, `checkedMultiply` emits the same hint. It applies to `toBytes` too:
bytes is the smallest unit, so the fix for an overflow is to convert to a
larger unit (e.g. `toMiB`) instead, as the existing `UtilsSuite` overflow test
shows (`PiB.toMiB(1073741824)` doesn't overflow).
##########
common/utils-java/src/main/java/org/apache/spark/network/util/ByteUnit.java:
##########
@@ -54,6 +54,10 @@ public long toBytes(long d) {
if (d < 0) {
throw new IllegalArgumentException("Negative size value. Size must be
positive: " + d);
}
+ if (Long.MAX_VALUE / multiplier < d) {
+ throw new IllegalArgumentException("Conversion of " + d + " " + name()
Review Comment:
Good call, extracted the shared check into a private `checkedMultiply(d,
factor)` that both `convertTo` and `toBytes` use now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]