diff --git a/include/boost/regex/v5/basic_regex_creator.hpp b/include/boost/regex/v5/basic_regex_creator.hpp index 82306d36..bb76c7c1 100644 --- a/include/boost/regex/v5/basic_regex_creator.hpp +++ b/include/boost/regex/v5/basic_regex_creator.hpp @@ -1019,6 +1019,8 @@ int basic_regex_creator::calculate_backstep(re_syntax_base* state { if(rep->max != rep->min) return -1; + if (static_cast((std::numeric_limits::max)() - result) < rep->min) + return -1; // protection against overflow, we can't calculate a backstep in this case and the expression is probably ill-formed. result += static_cast(rep->min); state = rep->alt.p; continue;