Opened 6 years ago

Last modified 6 years ago

#12582 new Bugs

Error catching specific "regex_error"

Reported by: Pierre Vaillancourt <pierre.vaillancourt@…> Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.61.0 Severity: Regression
Keywords: regex_error Cc:

Description

The following try catch doesn't work in 1.61, but did work in 1.55. Other boost exceptions are caught properly. I've provided two examples (one working, one failing)

Exception is never caught

try
{
  boost::smatch m1;

  std::string long_String= "@VOOfPHslmjhdQGM4CHjMII4tf-5-FjBnxaC6D8C3jQs09cdw8gDlF0bI7jfmN6cGKeZdJVOCt5GoeOVA3ao35rN-NV3Oy3A9V2hMUO0hHHVdWeGSoRY8ua3lnsXZsaOmz9YTZhR-Xtq13xAnYP5sHHbfM6tuuqWetdgCGNeMlckGyEKBW0MTtRq7Lhns8t7QW_59x77LRz2n0LtSS46sdN970eQ04llaeXZQDUv4coz6VuOBmEUUfLcxxc3HACSqdLQ-EmD_olxqPjR_mO2_ltjv_m2edvtn-5psCXZVpdVLKtcjl8ezLJQx5l30tIiPWkLDP_jot-lUe7ypMjXY68fo_E33L3eIyVTzyCWLSQdC9616-xA9gpMlHLDYOZL9MsxeOsK5v86OYkTn88IDtWV_bXfdEsN9m_p1CYKjwyhlBWH1h3uSz0WAzcIqqMDkNbQrF8sFmX7fVSC5OhazMnJHRnfcKCHfyCoTqA5horkQn0Kded3qFdtnZEvrOKgrGeiLjNwwlPuRQI2pD9StWHiI5b2ACyJ2wV8Xl7f4FKhr3H6xXpWKTEXNt4VjWZgfcVq9UCiThSLEBfHOEe1voARPHrDBw26VSjHVWacUZAAJ6Cf4AXsx8kvBsiw4HKyG6qdlYp6v03BEtLv_vP2neOGrDQAV5s9ED_qGGJVDgAxb_auZwL5lNE5Sw0KdWDBd";

  static const boost::regex b1("((?:[A-z0-9]+|[A-z\\-]+ ?)?(?: the )?(?:[Ss][Pp][Ii][Dd][Ee][Rr]|[Ss]crape|[A-Za-z0-9-]*(?:[^C][^Uu])[Bb]ot|[Cc][Rr][Aa][Ww][Ll])[A-z0-9]*)(?:(?:[ /]| v)(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?)?");
       
  boost::regex_search(sample_kaspersky, m1, b1);
}
catch (...)
{
  //should catch a regex_error: The complexity of matching the regular expression exceeded predefined bounds....
}

The previous code block doesn't catch the exception but instead calls terminate:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >' what(): The complexity of matching the regular expression exceeded predefined bounds.  Try refactoring the regular expression to make each choice made by the state machine unambiguous.  This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate.

Exception is caught properly

    try
    {
        // forcing an exception
        static const boost::regex b2("((?:[?)?)?");
        boost::smatch m2;
        boost::regex_search(sample_kaspersky, m2, b2);
    }
    catch (...)
    {
        //this work perfectly
    }

Change History (1)

comment:1 by John Maddock, 6 years ago

With apologies for the delay, this works fine for me here, what compiler/platform are you using?

This smells like an installation error (linking against the wrong regex lib version).

Note: See TracTickets for help on using tickets.