mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-11 17:02:25 +00:00
Added range check for extractGroups function
This commit is contained in:
parent
2cb4c91c02
commit
1f0d95e5c3
@ -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);
|
||||
|
||||
|
14
tests/queries/0_stateless/01275_extract_groups_check.sql
Normal file
14
tests/queries/0_stateless/01275_extract_groups_check.sql
Normal file
@ -0,0 +1,14 @@
|
||||
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 }
|
Loading…
Reference in New Issue
Block a user