This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new bc032a98e05 [fix](function)When sublength in substr() is negative, will casue mem… (#31316) bc032a98e05 is described below commit bc032a98e055b87ef472019d1d2851b7f67c2aa3 Author: xuwei <13474478...@163.com> AuthorDate: Sat Feb 24 14:16:36 2024 +0800 [fix](function)When sublength in substr() is negative, will casue mem… (#31316) * [fix](function)When sublength in substr() is negative, will casue memory out of bounds, same as left() * [fix](function)When sublength in substr() is negative, will casue memory out of bounds, same as left() add ut * Update function_string.h * Update function_string.h * Update function_string.h --------- Co-authored-by: yiguolei <676222...@qq.com> --- be/src/vec/functions/function_string.h | 3 ++- be/test/vec/function/function_string_test.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/be/src/vec/functions/function_string.h b/be/src/vec/functions/function_string.h index c48f42022e7..45b1dec4f88 100644 --- a/be/src/vec/functions/function_string.h +++ b/be/src/vec/functions/function_string.h @@ -282,7 +282,8 @@ private: int start_value = is_const ? start[0] : start[i]; int len_value = is_const ? len[0] : len[i]; - if (start_value > str_size || start_value < -str_size || str_size == 0) { + if (start_value > str_size || start_value < -str_size || str_size == 0 || + len_value <= 0) { StringOP::push_empty_string(i, res_chars, res_offsets); continue; } diff --git a/be/test/vec/function/function_string_test.cpp b/be/test/vec/function/function_string_test.cpp index 48647d7e2d1..03a580e5192 100644 --- a/be/test/vec/function/function_string_test.cpp +++ b/be/test/vec/function/function_string_test.cpp @@ -55,6 +55,8 @@ TEST(function_string_test, function_string_substr_test) { {{std::string(""), 0, 4}, std::string("")}, {{std::string("123"), 0, 4}, std::string("")}, {{std::string("123"), 1, 0}, std::string("")}, + {{std::string("123"), 1, -1}, std::string("")}, + {{std::string("你好好"), 1, -1}, std::string("")}, {{Null(), 5, 4}, Null()}}; check_function<DataTypeString, true>(func_name, input_types, data_set); @@ -105,6 +107,8 @@ TEST(function_string_test, function_string_strleft_test) { {{std::string(""), -2}, std::string("")}, {{std::string(""), 0}, std::string("")}, {{std::string("123"), 0}, std::string("")}, + {{std::string("123"), -1}, std::string("")}, + {{std::string("你好好"), -1}, std::string("")}, {{Null(), 3}, Null()}}; check_function<DataTypeString, true>(func_name, input_types, data_set); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org