mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Tighter sanity checks in matching code
This commit is contained in:
parent
35bef17302
commit
040fbf3686
@ -115,9 +115,13 @@ struct MatchImpl
|
|||||||
const ColumnPtr & start_pos_,
|
const ColumnPtr & start_pos_,
|
||||||
PaddedPODArray<UInt8> & res)
|
PaddedPODArray<UInt8> & res)
|
||||||
{
|
{
|
||||||
|
const size_t haystack_size = haystack_offsets.size();
|
||||||
|
|
||||||
|
if (haystack_size != res.size())
|
||||||
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Function '{}' unexpectedly received a different number of haystacks and results", name);
|
||||||
|
|
||||||
if (start_pos_ != nullptr)
|
if (start_pos_ != nullptr)
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function '{}' doesn't support start_pos argument", name);
|
||||||
"Function '{}' doesn't support start_pos argument", name);
|
|
||||||
|
|
||||||
if (haystack_offsets.empty())
|
if (haystack_offsets.empty())
|
||||||
return;
|
return;
|
||||||
@ -170,8 +174,6 @@ struct MatchImpl
|
|||||||
|
|
||||||
regexp->getAnalyzeResult(required_substring, is_trivial, required_substring_is_prefix);
|
regexp->getAnalyzeResult(required_substring, is_trivial, required_substring_is_prefix);
|
||||||
|
|
||||||
size_t haystack_size = haystack_offsets.size();
|
|
||||||
|
|
||||||
if (required_substring.empty())
|
if (required_substring.empty())
|
||||||
{
|
{
|
||||||
if (!regexp->getRE2()) /// An empty regexp. Always matches.
|
if (!regexp->getRE2()) /// An empty regexp. Always matches.
|
||||||
@ -270,6 +272,11 @@ struct MatchImpl
|
|||||||
const String & needle,
|
const String & needle,
|
||||||
PaddedPODArray<UInt8> & res)
|
PaddedPODArray<UInt8> & res)
|
||||||
{
|
{
|
||||||
|
const size_t haystack_size = haystack.size() / N;
|
||||||
|
|
||||||
|
if (haystack_size != res.size())
|
||||||
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Function '{}' unexpectedly received a different number of haystacks and results", name);
|
||||||
|
|
||||||
if (haystack.empty())
|
if (haystack.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -326,8 +333,6 @@ struct MatchImpl
|
|||||||
|
|
||||||
regexp->getAnalyzeResult(required_substring, is_trivial, required_substring_is_prefix);
|
regexp->getAnalyzeResult(required_substring, is_trivial, required_substring_is_prefix);
|
||||||
|
|
||||||
const size_t haystack_size = haystack.size() / N;
|
|
||||||
|
|
||||||
if (required_substring.empty())
|
if (required_substring.empty())
|
||||||
{
|
{
|
||||||
if (!regexp->getRE2()) /// An empty regexp. Always matches.
|
if (!regexp->getRE2()) /// An empty regexp. Always matches.
|
||||||
@ -433,13 +438,11 @@ struct MatchImpl
|
|||||||
{
|
{
|
||||||
const size_t haystack_size = haystack_offsets.size();
|
const size_t haystack_size = haystack_offsets.size();
|
||||||
|
|
||||||
if (haystack_size != needle_offset.size())
|
if (haystack_size != needle_offset.size() || haystack_size != res.size())
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Function '{}' unexpectedly received a different number of haystacks, needles and results", name);
|
||||||
"Function '{}' unexpectedly received a different number of haystacks and needles", name);
|
|
||||||
|
|
||||||
if (start_pos_ != nullptr)
|
if (start_pos_ != nullptr)
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function '{}' doesn't support start_pos argument", name);
|
||||||
"Function '{}' doesn't support start_pos argument", name);
|
|
||||||
|
|
||||||
if (haystack_offsets.empty())
|
if (haystack_offsets.empty())
|
||||||
return;
|
return;
|
||||||
@ -549,13 +552,11 @@ struct MatchImpl
|
|||||||
{
|
{
|
||||||
const size_t haystack_size = haystack.size()/N;
|
const size_t haystack_size = haystack.size()/N;
|
||||||
|
|
||||||
if (haystack_size != needle_offset.size())
|
if (haystack_size != needle_offset.size() || haystack_size != res.size())
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Function '{}' unexpectedly received a different number of haystacks, needles and results", name);
|
||||||
"Function '{}' unexpectedly received a different number of haystacks and needles", name);
|
|
||||||
|
|
||||||
if (start_pos_ != nullptr)
|
if (start_pos_ != nullptr)
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function '{}' doesn't support start_pos argument", name);
|
||||||
"Function '{}' doesn't support start_pos argument", name);
|
|
||||||
|
|
||||||
if (haystack.empty())
|
if (haystack.empty())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user