This is an automated email from the ASF dual-hosted git repository.
HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 3f330a74fde [fix](function) prevent count_substrings tail overmatch
(#63215)
3f330a74fde is described below
commit 3f330a74fdeffa0e0046cb5b7850a31e469d1317
Author: Asish Kumar <[email protected]>
AuthorDate: Wed Aug 26 15:00:09 2026 +0530
[fix](function) prevent count_substrings tail overmatch (#63215)
---
be/src/exprs/function/function_string_search.cpp | 9 ++++++++-
be/test/exprs/function/function_string_test.cpp | 6 ++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/be/src/exprs/function/function_string_search.cpp
b/be/src/exprs/function/function_string_search.cpp
index f3d39c7b381..2183494f811 100644
--- a/be/src/exprs/function/function_string_search.cpp
+++ b/be/src/exprs/function/function_string_search.cpp
@@ -831,11 +831,18 @@ private:
size_t find_pos(size_t pos, const StringRef str_ref, const StringRef
pattern_ref) const {
size_t old_size = pos;
size_t str_size = str_ref.size;
- while (pos < str_size &&
+ if (pattern_ref.size > str_size || pos > str_size - pattern_ref.size) {
+ return str_size - old_size;
+ }
+ const size_t last_match_pos = str_size - pattern_ref.size;
+ while (pos <= last_match_pos &&
memcmp_small_allow_overflow15((const uint8_t*)str_ref.data +
pos,
(const uint8_t*)pattern_ref.data,
pattern_ref.size)) {
pos++;
}
+ if (pos > last_match_pos) {
+ return str_size - old_size;
+ }
return pos - old_size;
}
diff --git a/be/test/exprs/function/function_string_test.cpp
b/be/test/exprs/function/function_string_test.cpp
index 67aed86467d..06298224fc5 100644
--- a/be/test/exprs/function/function_string_test.cpp
+++ b/be/test/exprs/function/function_string_test.cpp
@@ -3816,6 +3816,9 @@ TEST(function_string_test, function_count_substring_test)
{
{{std::string("hello world"), std::string("")},
std::int32_t(0)},
{{std::string(""), std::string("l")},
std::int32_t(0)},
{{std::string(""), std::string("")},
std::int32_t(0)},
+ {{std::string("ccc"), std::string("cc")},
std::int32_t(1)},
+ {{std::string("aaaa"), std::string("aa")},
std::int32_t(2)},
+ {{std::string("ab"), std::string("abc")},
std::int32_t(0)},
// utf-8 characters
{{std::string("你好123世界"), std::string("世")},
std::int32_t(1)},
{{std::string("你好123世界"), std::string("你")},
std::int32_t(1)},
@@ -3841,6 +3844,9 @@ TEST(function_string_test, function_count_substring_test)
{
{{std::string("hello world"), std::string(""),
std::int32_t(0)}, std::int32_t(0)},
{{std::string(""), std::string("l"), std::int32_t(1)},
std::int32_t(0)},
{{std::string(""), std::string(""), std::int32_t(1)},
std::int32_t(0)},
+ {{std::string("ccc"), std::string("cc"), std::int32_t(1)},
std::int32_t(1)},
+ {{std::string("ccc"), std::string("cc"), std::int32_t(3)},
std::int32_t(0)},
+ {{std::string("ab"), std::string("abc"), std::int32_t(1)},
std::int32_t(0)},
// utf-8 characters
{{std::string("你好123世界"), std::string("世"), std::int32_t(3)},
std::int32_t(1)},
{{std::string("你好123世界"), std::string("你"), std::int32_t(1)},
std::int32_t(1)},
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]