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

            Bug ID: 70411
           Summary: Stack overflow with std::regex_match
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bisqwit at iki dot fi
  Target Milestone: ---

When running this code, libstdc++ crashes with a stack overflow (segmentation
fault) in std::regex_match. This regular expression is not the type that should
require exponential backtracking.

Crash occurs in code compiled by GCC 5.3.1 on x86_64-linux-gnu. Clang++ does
the same crash, when using libstdc++ from GCC.

Code compiled by GCC 4.9 does _not_ produce a crash, as it evidently uses a
different version of libstdc++.

    #include <regex>
    #include <string>

    std::string make_test_string()
    {
        std::string result = "00000000 16777216 10000 ";
        for(unsigned n=0; n<10000; ++n) result += "EA       NOP%";
        return result;
    }
    std::regex testregex("^([0-9A-F]+) +([0-9]+) +([0-9]+) (.*)$");

    int main()
    {
        std::string teststr = make_test_string();

        std::smatch res;
        std::regex_match(teststr, res, testregex);
    }

Reply via email to