Caideyipi commented on code in PR #18589:
URL: https://github.com/apache/iotdb/pull/18589#discussion_r3964058122


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java:
##########
@@ -591,32 +592,40 @@ public static long convertDurationStrToLong(
    */
   public static long convertDurationStrToLong(
       long currentTime, String duration, String timestampPrecision, boolean 
convertYearToMonth) {
-    long total = 0;
-    long temp = 0;
-    for (int i = 0; i < duration.length(); i++) {
-      char ch = duration.charAt(i);
-      if (Character.isDigit(ch)) {
-        temp *= 10;
-        temp += (ch - '0');
-      } else {
-        String unit = String.valueOf(duration.charAt(i));
-        // This is to identify units with two letters.
-        if (i + 1 < duration.length() && !Character.isDigit(duration.charAt(i 
+ 1))) {
-          i++;
-          unit += duration.charAt(i);
-        }
-        unit = unit.toLowerCase();
-        if (convertYearToMonth && unit.equals("y")) {
-          temp *= 12;
-          unit = "mo";
+    try {
+      long total = 0;
+      long temp = 0;
+      for (int i = 0; i < duration.length(); i++) {
+        char ch = duration.charAt(i);
+        if (Character.isDigit(ch)) {
+          temp = Math.addExact(Math.multiplyExact(temp, 10), 
Character.digit(ch, 10));
+        } else {
+          String unit = String.valueOf(duration.charAt(i));
+          // This is to identify units with two letters.
+          if (i + 1 < duration.length() && 
!Character.isDigit(duration.charAt(i + 1))) {
+            i++;
+            unit += duration.charAt(i);
+          }
+          unit = unit.toLowerCase();
+          if (convertYearToMonth && unit.equals("y")) {
+            temp = Math.multiplyExact(temp, 12);
+            unit = "mo";
+          }
+          total =
+              Math.addExact(
+                  total,
+                  DateTimeUtils.convertDurationStrToLong(
+                      currentTime == -1 ? -1 : Math.addExact(currentTime, 
total),

Review Comment:
   Fixed in 7b3c9a2208f. Duration parsing now passes a reference timestamp only 
for calendar-dependent month units; fixed-duration components are evaluated 
without the intermediate currentTime + total calculation. The final 
date-expression addition/subtraction remains checked by the caller, so a valid 
subtraction is no longer rejected by an unused intermediate overflow.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to