Skip to content

Commit

Permalink
expression: fix substring_index crash tiflash in some case (#9137) (#…
Browse files Browse the repository at this point in the history
…9141)

close #9116

Fix tiflash crash caused by function `substring_index` in some corner cases

Co-authored-by: wshwsh12 <793703860@qq.com>
  • Loading branch information
ti-chi-bot and wshwsh12 authored Jun 12, 2024
1 parent c5885bb commit 1603952
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dbms/src/Functions/FunctionsString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4868,6 +4868,7 @@ class FunctionSubStringIndex : public IFunction
const UInt8 * pos = begin;
const UInt8 * end = pos + data_size;
assert(delim_size != 0);
assert(count != 0);
if (count > 0)
{
// Fast exit when count * delim_size > data_size
Expand All @@ -4883,10 +4884,11 @@ class FunctionSubStringIndex : public IFunction
if (match == end || count == 0)
{
copyDataToResult(res_data, res_offset, begin, match);
break;
return;
}
pos = match + delim_size;
}
copyDataToResult(res_data, res_offset, begin, end);
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Functions/tests/gtest_substring_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ try
createColumn<Nullable<String>>({"www.pingcap.com", "www...www", "中文.测.试。。。", "www.www"}),
createColumn<Nullable<String>>({"", "", "", ""}),
createColumn<Nullable<Int64>>({2, 2, 2, 2})));

// Test issue 9116
ASSERT_COLUMN_EQ(
createColumn<Nullable<String>>({"aaabbba", "aaabbbaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa"}),
executeFunction(
func_name,
createColumn<Nullable<String>>({"aaabbbaaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa"}),
createColumn<Nullable<String>>({"a", "a", "a", "a", "a"}),
createColumn<Nullable<Int64>>({5, 6, 7, 8, 9})));
}
CATCH

Expand Down

0 comments on commit 1603952

Please sign in to comment.