2022-06-24 13:24:17 +00:00
|
|
|
#include <Functions/checkHyperscanRegexp.h>
|
2021-08-07 05:07:41 +00:00
|
|
|
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:24:17 +00:00
|
|
|
void checkHyperscanRegexp(const std::vector<std::string_view> & regexps, size_t max_hyperscan_regexp_length, size_t max_hyperscan_regexp_total_length)
|
2021-08-07 05:07:41 +00:00
|
|
|
{
|
|
|
|
if (max_hyperscan_regexp_length > 0 || max_hyperscan_regexp_total_length > 0)
|
|
|
|
{
|
|
|
|
size_t total_regexp_length = 0;
|
2022-06-24 13:16:57 +00:00
|
|
|
for (const auto & regexp : regexps)
|
2021-08-07 05:07:41 +00:00
|
|
|
{
|
2022-06-24 13:16:57 +00:00
|
|
|
if (max_hyperscan_regexp_length > 0 && regexp.size() > max_hyperscan_regexp_length)
|
2023-01-26 19:20:56 +00:00
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Regexp length too large ({} > {})", regexp.size(), max_hyperscan_regexp_length);
|
2022-06-24 13:16:57 +00:00
|
|
|
total_regexp_length += regexp.size();
|
2021-08-07 05:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_hyperscan_regexp_total_length > 0 && total_regexp_length > max_hyperscan_regexp_total_length)
|
2023-01-26 19:20:56 +00:00
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Total regexp lengths too large ({} > {})",
|
|
|
|
total_regexp_length, max_hyperscan_regexp_total_length);
|
2021-08-07 05:07:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|