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
…9140)

close #9116

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

Co-authored-by: wshwsh12 <793703860@qq.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 13, 2024
1 parent d276752 commit 3962fba
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 @@ -5268,6 +5268,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 @@ -5283,10 +5284,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 @@ -364,6 +364,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 3962fba

Please sign in to comment.