[Boost-bugs] [Boost C++ Libraries] #12582: Error catching specific "regex_error"

Subject: [Boost-bugs] [Boost C++ Libraries] #12582: Error catching specific "regex_error"
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-11-04 14:58:54


#12582: Error catching specific "regex_error"
-------------------------------------------------+-------------------------
 Reporter: Pierre Vaillancourt | Owner: johnmaddock
  <pierre.vaillancourt@…> | Status: new
     Type: Bugs | Component: regex
Milestone: To Be Determined | Severity: Regression
  Version: Boost 1.61.0 |
 Keywords: regex_error |
-------------------------------------------------+-------------------------
 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
     }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12582>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC