fixes possible data truncation (#11462)

* fixes possible data truncation

* fixes possible data truncation

* add unit test case to catch the possible data truncation
This commit is contained in:
Sandeep 2021-08-26 20:16:26 +08:00 committed by GitHub
parent 2a658acad4
commit ac2b65e837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -219,6 +219,9 @@ public interface Function
protected ExprEval eval(double param)
{
if (param < Long.MIN_VALUE || param > Long.MAX_VALUE) {
throw new IAE("Possible data truncation, param [%f] is out of long value range", param);
}
return eval((long) param);
}

View File

@ -746,6 +746,15 @@ public class FunctionTest extends InitializedNullHandlingTest
assertExpr("bitwiseComplement('1')", null);
assertExpr("bitwiseComplement(null)", null);
// data truncation
try {
assertExpr("bitwiseComplement(461168601842738800000000000000.000000)", null);
Assert.fail("Did not throw IllegalArgumentException");
}
catch (IllegalArgumentException e) {
Assert.assertEquals("Possible data truncation, param [461168601842738800000000000000.000000] is out of long value range", e.getMessage());
}
// doubles are cast
assertExpr("bitwiseOr(2.345, 1)", 3L);
assertExpr("bitwiseOr(2, 1.3)", 3L);