You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/03/02 16:45:25 UTC

[doris] 09/09: [fix](expr) avoid crashing caused by big depth of expression tree (#17314)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 98a7bb4816b0eb749c4b224eb5d2d33bc69350a5
Author: Jerry Hu <mr...@gmail.com>
AuthorDate: Thu Mar 2 16:55:53 2023 +0800

    [fix](expr) avoid crashing caused by big depth of expression tree (#17314)
---
 be/src/common/config.h           | 3 +++
 be/src/vec/exprs/vexpr.cpp       | 8 ++++++++
 be/src/vec/exprs/vexpr_context.h | 3 +++
 3 files changed, 14 insertions(+)

diff --git a/be/src/common/config.h b/be/src/common/config.h
index 4a97529abc..aa0138db7c 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -905,6 +905,9 @@ CONF_Bool(enable_java_support, "true");
 // Set config randomly to check more issues in github workflow
 CONF_Bool(enable_fuzzy_mode, "false");
 
+// max depth of expression tree allowed.
+CONF_Int32(max_depth_of_expr_tree, "200");
+
 #ifdef BE_TEST
 // test s3
 CONF_String(test_s3_resource, "resource");
diff --git a/be/src/vec/exprs/vexpr.cpp b/be/src/vec/exprs/vexpr.cpp
index a91109291d..034a7df7b0 100644
--- a/be/src/vec/exprs/vexpr.cpp
+++ b/be/src/vec/exprs/vexpr.cpp
@@ -79,9 +79,17 @@ VExpr::VExpr(const TypeDescriptor& type, bool is_slotref, bool is_nullable)
 }
 
 Status VExpr::prepare(RuntimeState* state, const RowDescriptor& row_desc, VExprContext* context) {
+    ++context->_depth_num;
+    if (context->_depth_num > config::max_depth_of_expr_tree) {
+        return Status::InternalError(
+                "The depth of the expression tree is too big, make it less than {}",
+                config::max_depth_of_expr_tree);
+    }
+
     for (int i = 0; i < _children.size(); ++i) {
         RETURN_IF_ERROR(_children[i]->prepare(state, row_desc, context));
     }
+    --context->_depth_num;
     return Status::OK();
 }
 
diff --git a/be/src/vec/exprs/vexpr_context.h b/be/src/vec/exprs/vexpr_context.h
index 82ff9d11b8..d3aaa6a5d7 100644
--- a/be/src/vec/exprs/vexpr_context.h
+++ b/be/src/vec/exprs/vexpr_context.h
@@ -100,6 +100,9 @@ private:
 
     int _last_result_column_id;
 
+    /// The depth of expression-tree.
+    int _depth_num = 0;
+
     bool _stale;
 };
 } // namespace doris::vectorized


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org