Regex: Limit programs to std::numeric_limits<uint16_t>::max() instructions

This commit is contained in:
Maxime Coste 2017-10-12 21:21:52 +08:00
parent 8c8dcb3a84
commit b0233262b8
2 changed files with 4 additions and 1 deletions

View File

@ -531,6 +531,9 @@ struct RegexCompiler
{
compile_node(m_parsed_regex.ast);
push_inst(CompiledRegex::Match);
constexpr auto max_instructions = std::numeric_limits<uint16_t>::max();
if (m_program.instructions.size() >= max_instructions)
throw regex_error(format("regex compiled to more than {} instructions", max_instructions));
m_program.matchers = m_parsed_regex.matchers;
m_program.save_count = m_parsed_regex.capture_count * 2;
m_program.direction = direction;

View File

@ -235,7 +235,7 @@ private:
{
Vector<Thread> current_threads;
Vector<Thread> next_threads;
Vector<uint32_t> processed;
Vector<uint16_t> processed;
};
enum class StepResult { Consumed, Matched, Failed };