From 52e381e744238ab2555a918a06ff2a9a1ab592a4 Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Thu, 2 Mar 2023 10:05:13 +0800 Subject: [PATCH] [fix](expr) avoid crashing caused by big depth of expression tree --- 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 11d21b735960d3..1b6786b7d92411 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -930,6 +930,9 @@ CONF_Int32(num_broadcast_buffer, "32"); // semi-structure configs CONF_Bool(enable_parse_multi_dimession_array, "true"); +// max depth of expression tree allowed. +CONF_Int32(max_depth_of_expr_tree, "200"); + // Report a tablet as bad when io errors occurs more than this value. CONF_mInt64(max_tablet_io_errors, "-1"); diff --git a/be/src/vec/exprs/vexpr.cpp b/be/src/vec/exprs/vexpr.cpp index 4e71afbf315404..8511a8e317e742 100644 --- a/be/src/vec/exprs/vexpr.cpp +++ b/be/src/vec/exprs/vexpr.cpp @@ -85,9 +85,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 82ff9d11b8a68e..d3aaa6a5d72eac 100644 --- a/be/src/vec/exprs/vexpr_context.h +++ b/be/src/vec/exprs/vexpr_context.h @@ -100,6 +100,9 @@ class VExprContext { int _last_result_column_id; + /// The depth of expression-tree. + int _depth_num = 0; + bool _stale; }; } // namespace doris::vectorized