https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123895

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2026-01-30

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We could implement error_complexity with something like this (taken from Bug
78276 comment 6, where there are examples that hit this condition):

--- a/libstdc++-v3/include/bits/regex_executor.tcc
+++ b/libstdc++-v3/include/bits/regex_executor.tcc
@@ -626,9 +626,16 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
     _M_dfs(_Match_mode __match_mode, _StateIdT __start)
     {
       _M_frames.emplace_back(_S_fopcode_next, __start);
+      unsigned __steps = 0;
+      const auto __dist = std::distance(_M_begin, _M_end);

       while (!_M_frames.empty())
        {
+         ++__steps;
+         if (__steps >> 13 > __dist)
+           __throw_regex_error(regex_constants::error_complexity,
+                               "it's over 9000!");
+
          _ExecutorFrame<_BiIter> __frame = std::move(_M_frames.back());
          _M_frames.pop_back();


This scales with the input size, so that we keep going for longer on large
inputs. But if we exceed 16k steps per input character, give up and report an
error.

Reply via email to