From fd0608bba93653ab28e6cb5fc82459ba03fe7c0d Mon Sep 17 00:00:00 2001 From: cambyzju Date: Mon, 10 Apr 2023 17:51:29 +0800 Subject: [PATCH] apply pr17346 into non-vectorized engine, avoid crashing caused by big depth of expression tree --- be/src/exprs/expr.cpp | 8 ++++++++ be/src/exprs/expr_context.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/be/src/exprs/expr.cpp b/be/src/exprs/expr.cpp index 742906895946c0..754cf57167a4e3 100644 --- a/be/src/exprs/expr.cpp +++ b/be/src/exprs/expr.cpp @@ -516,9 +516,17 @@ Status Expr::prepare(const std::vector& ctxs, RuntimeState* state, Status Expr::prepare(RuntimeState* state, const RowDescriptor& row_desc, ExprContext* context) { DCHECK(_type.type != INVALID_TYPE); + ++context->_depth_num; + if (context->_depth_num > config::max_depth_of_expr_tree) { + return Status::InternalError( + fmt::format("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/exprs/expr_context.h b/be/src/exprs/expr_context.h index cced55dbeca14e..6e9df9a30cf210 100644 --- a/be/src/exprs/expr_context.h +++ b/be/src/exprs/expr_context.h @@ -186,6 +186,9 @@ class ExprContext { /// Calls the appropriate Get*Val() function on 'e' and stores the result in result_. /// This is used by Exprs to call GetValue() on a child expr, rather than root_. void* get_value(Expr* e, TupleRow* row); + + /// The depth of expression-tree. + int _depth_num = 0; }; inline void* ExprContext::get_value(TupleRow* row) {