You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/03/14 08:57:27 UTC
[iotdb] branch iotdb273213 created (now 3f66eb7)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a change to branch iotdb273213
in repository https://gitbox.apache.org/repos/asf/iotdb.git.
at 3f66eb7 [IOTDB-2732] Reject inserting an invalid infinity float value (#5210)
This branch includes the following new commits:
new 3f66eb7 [IOTDB-2732] Reject inserting an invalid infinity float value (#5210)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[iotdb] 01/01: [IOTDB-2732] Reject inserting an invalid infinity float value (#5210)
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch iotdb273213
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 3f66eb7a530998dd2648494d8c11d514892b672b
Author: Haonan <hh...@outlook.com>
AuthorDate: Mon Mar 14 16:35:00 2022 +0800
[IOTDB-2732] Reject inserting an invalid infinity float value (#5210)
---
.../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))) {