This is an automated email from the ASF dual-hosted git repository.
asdf2014 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new ac2b65e fixes possible data truncation (#11462)
ac2b65e is described below
commit ac2b65e837731074b9604b0cc290e448adcba703
Author: Sandeep <[email protected]>
AuthorDate: Thu Aug 26 20:16:26 2021 +0800
fixes possible data truncation (#11462)
* fixes possible data truncation
* fixes possible data truncation
* add unit test case to catch the possible data truncation
---
core/src/main/java/org/apache/druid/math/expr/Function.java | 3 +++
core/src/test/java/org/apache/druid/math/expr/FunctionTest.java | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/core/src/main/java/org/apache/druid/math/expr/Function.java
b/core/src/main/java/org/apache/druid/math/expr/Function.java
index 9e4a241..99f9eac 100644
--- a/core/src/main/java/org/apache/druid/math/expr/Function.java
+++ b/core/src/main/java/org/apache/druid/math/expr/Function.java
@@ -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);
}
diff --git a/core/src/test/java/org/apache/druid/math/expr/FunctionTest.java
b/core/src/test/java/org/apache/druid/math/expr/FunctionTest.java
index a5a9fce..82d7fba 100644
--- a/core/src/test/java/org/apache/druid/math/expr/FunctionTest.java
+++ b/core/src/test/java/org/apache/druid/math/expr/FunctionTest.java
@@ -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);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]