Boost C++ Libraries: Ticket #7758: Regex will create stack error after upgrade of boost https://svn.boost.org/trac10/ticket/7758 <p> This regex .*?\r\n(version .*?\r\n) will create a stack error using boost 1.44 or 1.52. It did work using boost 1.31. </p> <p> I used the following method to get the tokens: boost::sregex_iterator a_RegIterator( a_InputString.begin(), a_InputString.end(), a_Expression, a_RegExMatchFlags ); </p> <p> Setting the match flag match_single_line will work, too. It looks like the error will show up if the input text is rather large (100kb...). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7758 Trac 1.4.3 david.ecker@… Mon, 03 Dec 2012 14:00:49 GMT attachment set https://svn.boost.org/trac10/ticket/7758 https://svn.boost.org/trac10/ticket/7758 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">BoostRegexTest.cpp</span> </li> </ul> <p> cpp file </p> Ticket david.ecker@… Mon, 03 Dec 2012 14:04:04 GMT attachment set https://svn.boost.org/trac10/ticket/7758 https://svn.boost.org/trac10/ticket/7758 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Session.txt</span> </li> </ul> <p> Input File </p> Ticket david.ecker@… Mon, 03 Dec 2012 14:13:37 GMT <link>https://svn.boost.org/trac10/ticket/7758#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7758#comment:1</guid> <description> <p> I am testing using Visual Studio 2010, 64bit. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 03 Dec 2012 16:56:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7758#comment:2 https://svn.boost.org/trac10/ticket/7758#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The program throws a std::runtime_error because the match was taking too long to find - without a try-catch block around the code there is a stack error (I don't understand that one), but with a try-catch block the exception is caught and everything is behaving as expected. </p> <p> Is there a reason for the leading .* in the expression? It serves no good purpose other than to make the expression harder to match - you can get the same information from match_results::prefix() and way better performance. </p> Ticket david.ecker@… Mon, 03 Dec 2012 20:59:12 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/7758#comment:3 https://svn.boost.org/trac10/ticket/7758#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <p> I haven't posted the whole code. Catching the exception is not really the problem. The user ist able to enter his own regex for a defined job. I just posted one as an example. With this regex he can describe what parts of the text are to be extracted or replaced or used further on. </p> <p> The main problem is, that a whole bunch of different configured jobs exist, since it did work fast with boost 1.31. I can't really upgrade boost, because it will break existing user defined regex jobs. </p> Ticket anonymous Tue, 04 Dec 2012 16:46:31 GMT <link>https://svn.boost.org/trac10/ticket/7758#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7758#comment:4</guid> <description> <p> Investigating some more I believe you are correct - I'm testing a fix now (there's an optimization heuristic that's used almost everywhere else, but not for .* for some strange reason). </p> <p> In the mean time, try building both Boost and your code with BOOST_REGEX_RECURSIVE defined as the issue doesn't occur in the stack-recursive implementation. Unfortunately, you should be aware that that implementation (with BOOST_REGEX_RECURSIVE defined) isn't really considered safe to use with VC10, as it's harder to safely trap stack overflows (and throw an exception) than it was in earlier Visual Studio releases. Of course nearly every other regex implementation out there is stack recursive and also has this issue... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 04 Dec 2012 16:51:20 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7758#comment:5 https://svn.boost.org/trac10/ticket/7758#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/81705" title="Add missing optimization for leading .* repeats. Fixes #7758.">[81705]</a>) Add missing optimization for leading .* repeats. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7758" title="#7758: Bugs: Regex will create stack error after upgrade of boost (closed: fixed)">#7758</a>. </p> Ticket