github-code-scanning[bot] commented on code in PR #13952:
URL: https://github.com/apache/druid/pull/13952#discussion_r1153178104


##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -577,25 +623,47 @@
       );
     }
 
-    final RowSignature signature = toolChest.resultArraySignature(query);
-
-    final ArrayList<Object[]> resultList = new ArrayList<>();
-
-    toolChest.resultsAsArrays(query, results).accumulate(
-        resultList,
-        (acc, in) -> {
-          if (limitAccumulator.getAndIncrement() >= limitToUse) {
-            throw ResourceLimitExceededException.withMessage(
-                "Subquery generated results beyond maximum[%d]",
-                limitToUse
-            );
-          }
-          acc.add(in);
-          return acc;
+    if (memoryLimitAccumulator.get() >= memoryLimitToUse) {
+      throw ResourceLimitExceededException.withMessage(
+          "Cannot issue subquery, maximum subquery result bytes[%d] reached",
+          memoryLimitToUse
+      );
+    }
+
+    final List<Object[]> resultList = toolChest.resultsAsArrays(query, 
results).toList();
+
+    if (limitAccumulator.addAndGet(resultList.size()) >= limitToUse) {
+      throw ResourceLimitExceededException.withMessage(
+          "Subquery generated results beyond maximum[%d] rows",
+          limitToUse
+      );
+    }
+
+    FramesBackedInlineDataSource dataSource = null;
+    // Try to serialize the results into a frame only if the memory limit is 
set on the server or the query
+    if (memoryLimitSet || true) {

Review Comment:
   ## Expression always evaluates to the same value
   
   Expression always evaluates to the same value.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4491)



##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -577,25 +623,47 @@
       );
     }
 
-    final RowSignature signature = toolChest.resultArraySignature(query);
-
-    final ArrayList<Object[]> resultList = new ArrayList<>();
-
-    toolChest.resultsAsArrays(query, results).accumulate(
-        resultList,
-        (acc, in) -> {
-          if (limitAccumulator.getAndIncrement() >= limitToUse) {
-            throw ResourceLimitExceededException.withMessage(
-                "Subquery generated results beyond maximum[%d]",
-                limitToUse
-            );
-          }
-          acc.add(in);
-          return acc;
+    if (memoryLimitAccumulator.get() >= memoryLimitToUse) {
+      throw ResourceLimitExceededException.withMessage(
+          "Cannot issue subquery, maximum subquery result bytes[%d] reached",
+          memoryLimitToUse
+      );
+    }
+
+    final List<Object[]> resultList = toolChest.resultsAsArrays(query, 
results).toList();
+
+    if (limitAccumulator.addAndGet(resultList.size()) >= limitToUse) {
+      throw ResourceLimitExceededException.withMessage(
+          "Subquery generated results beyond maximum[%d] rows",
+          limitToUse
+      );
+    }
+
+    FramesBackedInlineDataSource dataSource = null;
+    // Try to serialize the results into a frame only if the memory limit is 
set on the server or the query
+    if (memoryLimitSet || true) {
+      try {
+        Sequence<FrameSignaturePair> frames = toolChest.resultsAsFrames(query, 
results);
+        Long memoryUsed = frames.accumulate(0L, ((accumulated, in) -> 
accumulated + in.getFrame().numBytes()));

Review Comment:
   ## User-controlled data in arithmetic expression
   
   This arithmetic expression depends on a [user-provided value](1), 
potentially causing an overflow.
   This arithmetic expression depends on a [user-provided value](2), 
potentially causing an overflow.
   This arithmetic expression depends on a [user-provided value](3), 
potentially causing an overflow.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4499)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to