未验证 提交 5992bae6 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #10736 from ClickHouse/extract-groups-range-check

Added range check for extractGroups function
......@@ -18,6 +18,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
extern const int BAD_ARGUMENTS;
}
......@@ -64,8 +65,15 @@ public:
const auto regexp = Regexps::get<false, false>(needle);
const auto & re2 = regexp->getRE2();
if (!re2)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
const size_t groups_count = re2->NumberOfCapturingGroups();
if (!groups_count)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
// Including 0-group, which is the whole regexp.
PODArrayWithStackMemory<re2_st::StringPiece, 128> matched_groups(groups_count + 1);
......
......@@ -18,6 +18,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
extern const int BAD_ARGUMENTS;
}
......@@ -64,8 +65,15 @@ public:
const auto regexp = Regexps::get<false, false>(needle);
const auto & re2 = regexp->getRE2();
if (!re2)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
const size_t groups_count = re2->NumberOfCapturingGroups();
if (!groups_count)
throw Exception("There is no groups in regexp: " + needle, ErrorCodes::BAD_ARGUMENTS);
// Including 0-group, which is the whole regexp.
PODArrayWithStackMemory<re2_st::StringPiece, 128> matched_groups(groups_count + 1);
......
0 groups, zero matches
[[],[]]
1 group, multiple matches, String and FixedString
[['hello'],['world']]
[['hello'],['world']]
......
......@@ -4,10 +4,10 @@ SELECT extractAllGroups('hello'); --{serverError 42} not enough arguments
SELECT extractAllGroups('hello', 123); --{serverError 43} invalid argument type
SELECT extractAllGroups(123, 'world'); --{serverError 43} invalid argument type
SELECT extractAllGroups('hello world', '((('); --{serverError 427} invalid re
SELECT extractAllGroups('hello world', materialize('\\w+')); --{serverError 44} non-cons needle
SELECT extractAllGroups('hello world', materialize('\\w+')); --{serverError 44} non-const needle
SELECT '0 groups, zero matches';
SELECT extractAllGroups('hello world', '\\w+');
SELECT extractAllGroups('hello world', '\\w+'); -- { serverError 36 }
SELECT '1 group, multiple matches, String and FixedString';
SELECT extractAllGroups('hello world', '(\\w+)');
......
0 groups, zero matches
[]
1 group, multiple matches, String and FixedString
['hello','world']
['hello','world']
......
......@@ -4,10 +4,10 @@ SELECT extractGroups('hello'); --{serverError 42} not enough arguments
SELECT extractGroups('hello', 123); --{serverError 43} invalid argument type
SELECT extractGroups(123, 'world'); --{serverError 43} invalid argument type
SELECT extractGroups('hello world', '((('); --{serverError 427} invalid re
SELECT extractGroups('hello world', materialize('\\w+')); --{serverError 44} non-cons needle
SELECT extractGroups('hello world', materialize('\\w+')); --{serverError 44} non-const needle
SELECT '0 groups, zero matches';
SELECT extractGroups('hello world', '\\w+');
SELECT extractGroups('hello world', '\\w+'); -- { serverError 36 }
SELECT '1 group, multiple matches, String and FixedString';
SELECT extractGroups('hello world', '(\\w+) (\\w+)');
......
SELECT extractGroups('hello', ''); -- { serverError 69 }
SELECT extractAllGroups('hello', ''); -- { serverError 69 }
SELECT extractGroups('hello', ' '); -- { serverError 36 }
SELECT extractAllGroups('hello', ' '); -- { serverError 36 }
SELECT extractGroups('hello', '\0'); -- { serverError 36 }
SELECT extractAllGroups('hello', '\0'); -- { serverError 36 }
SELECT extractGroups('hello', 'world'); -- { serverError 36 }
SELECT extractAllGroups('hello', 'world'); -- { serverError 36 }
SELECT extractGroups('hello', 'hello|world'); -- { serverError 36 }
SELECT extractAllGroups('hello', 'hello|world'); -- { serverError 36 }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册