jt2594838 commented on a change in pull request #2859:
URL: https://github.com/apache/iotdb/pull/2859#discussion_r597385370



##########
File path: 
server/src/main/java/org/apache/iotdb/db/query/dataset/RawQueryDataSetWithValueFilter.java
##########
@@ -127,13 +126,17 @@ private boolean cacheRowRecords() throws IOException {
       }
     }
     // 4. remove rowRecord if all values in one timestamp are null
-    for (int i = 0; i < cachedTimeCnt; i++) {
+    // traverse in reversed order to get element efficiently
+    for (int i = cachedTimeCnt - 1; i >= 0; i--) {
       if (hasField[i]) {
         cachedRowRecords.add(rowRecords[i]);
       }
     }
 
     // 5. check whether there is next row record
+    if (cachedRowRecords.isEmpty() && timeGenerator.hasNext()) {
+      return cacheRowRecords();
+    }

Review comment:
       Using recursion may have a potential problem in corner cases. 
   Assuming the fetch size is 100, but the first 1 000 000 records are all 
empty, so the method will be called recursively for 10000 times, resulting in a 
very deep stack that may overflow.
   It may not be frequent in real situations, but can be a weak point for 
attacks.




-- 
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.

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


Reply via email to