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 05:32:38 UTC

[iotdb] branch iotdb2732 created (now 7a2254f)

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a change to branch iotdb2732
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 7a2254f  [IOTDB-2732] Reject inserting an invalid infinity float value

This branch includes the following new commits:

     new 7a2254f  [IOTDB-2732] Reject inserting an invalid infinity float value

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

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch iotdb2732
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 7a2254f3caaacb635e23d4e99022e6ff1a38c363
Author: HTHou <hh...@outlook.com>
AuthorDate: Mon Mar 14 13:31:41 2022 +0800

    [IOTDB-2732] Reject inserting an invalid infinity float value
---
 .../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..8f0de1b 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
@@ -165,4 +165,30 @@ public class IOTDBInsertIT {
       Assert.assertEquals("411: Insertion contains duplicated measurement: status", e.getMessage());
     }
   }
+
+  @Test
+  public void testInsertInfinityFloatValue() {
+    try (Statement st1 = connection.createStatement()) {
+      st1.execute("CREATE TIMESERIES root.t1.wf01.wt01.f1 WITH DATATYPE=FLOAT, ENCODING=PLAIN");
+      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("CREATE TIMESERIES root.t1.wf01.wt01.d1 WITH DATATYPE=DOUBLE, ENCODING=PLAIN");
+      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))) {