This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.13 by this push:
new 64fa140 [IOTDB-2732] Reject inserting an invalid infinity float value
(#5210) (#5217)
64fa140 is described below
commit 64fa140a6bfaad8b09e1493ffb53532f997e58ef
Author: Haonan <[email protected]>
AuthorDate: Mon Mar 14 22:16:14 2022 +0800
[IOTDB-2732] Reject inserting an invalid infinity float value (#5210)
(#5217)
---
.../apache/iotdb/db/integration/IOTDBInsertIT.java | 26 ++++++++++++++++++++++
.../org/apache/iotdb/db/utils/CommonUtils.java | 12 ++++++++--
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git
a/integration/src/test/java/org/apache/iotdb/db/integration/IOTDBInsertIT.java
b/integration/src/test/java/org/apache/iotdb/db/integration/IOTDBInsertIT.java
index d3a5f39..9d26d4b 100644
---
a/integration/src/test/java/org/apache/iotdb/db/integration/IOTDBInsertIT.java
+++
b/integration/src/test/java/org/apache/iotdb/db/integration/IOTDBInsertIT.java
@@ -77,6 +77,8 @@ public class IOTDBInsertIT {
sqls.add("SET STORAGE GROUP TO root.t1");
sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.status WITH
DATATYPE=BOOLEAN, ENCODING=PLAIN");
sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH
DATATYPE=FLOAT, ENCODING=RLE");
+ sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.f1 WITH DATATYPE=FLOAT,
ENCODING=PLAIN");
+ sqls.add("CREATE TIMESERIES root.t1.wf01.wt01.d1 WITH DATATYPE=DOUBLE,
ENCODING=PLAIN");
}
private static void insertData() throws SQLException {
@@ -165,4 +167,28 @@ public class IOTDBInsertIT {
Assert.assertEquals("411: Insertion contains duplicated measurement:
status", e.getMessage());
}
}
+
+ @Test
+ public void testInsertInfinityFloatValue() {
+ try (Statement st1 = connection.createStatement()) {
+ st1.execute("insert into root.t1.wf01.wt01(time, f1) values(100,
3.4028235E300)");
+ Assert.fail();
+ } catch (SQLException e) {
+ Assert.assertEquals(
+ "313: failed to insert measurements [f1] caused by The input float
value is Infinity",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInsertInfinityDoubleValue() {
+ try (Statement st1 = connection.createStatement()) {
+ st1.execute("insert into root.t1.wf01.wt01(time, d1) values(100,
3.4028235E6000)");
+ Assert.fail();
+ } catch (SQLException e) {
+ Assert.assertEquals(
+ "313: failed to insert measurements [d1] caused by The input double
value is Infinity",
+ e.getMessage());
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
b/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
index 23a34f7..5617d75 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
@@ -104,9 +104,17 @@ public class CommonUtils {
case INT64:
return Long.parseLong(StringUtils.trim(value));
case FLOAT:
- return Float.parseFloat(value);
+ float f = Float.parseFloat(value);
+ if (Float.isInfinite(f)) {
+ throw new NumberFormatException("The input float value is
Infinity");
+ }
+ return f;
case DOUBLE:
- return Double.parseDouble(value);
+ double d = Double.parseDouble(value);
+ if (Double.isInfinite(d)) {
+ throw new NumberFormatException("The input double value is
Infinity");
+ }
+ return d;
case TEXT:
if ((value.startsWith(SQLConstant.QUOTE) &&
value.endsWith(SQLConstant.QUOTE))
|| (value.startsWith(SQLConstant.DQUOTE) &&
value.endsWith(SQLConstant.DQUOTE))) {