Boost C++ Libraries: Ticket #1498: xml parser: iteration instead of recursion in 'content' rule https://svn.boost.org/trac10/ticket/1498 <p> The 'content' rule in basic_xml_grammar.ipp contains a recursion, which leads to stack overflows if the serialized data contains many escaped characters. </p> <p> The end user of our application may serialize arbitrary binary data, and the msvc linker limits the stack size to 1 MB by default. Deserialization of a std::string containing the Verdana.ttf font file that comes with every Windows installation fails, it requires about 2 Mb of stack space. While it is possible to increase the stack size of the executable it still would not ensure the deserialization of arbitrary data. </p> <p> Proposed change: The 'content' rule matches the delimiter '&lt;' or a sequence of one or more 'Reference' or 'CharData' rules followed by the delimiter '&lt;'. This requires both 'Reference' and 'CharData' to not match an empty string, thus the 'CharDataChars' rule uses the Positive operator instead of the Kleene star. The use of 'CharData' in the rule 'UnusedAttribute' has to be adapted by prepending 'CharData' with the Optional operator. </p> <p> Effect: Only the deserialization is affected, serialized files are identical. The 'content' rule iterates over the data instead of recursing into itself, which requires less than 128 Kb stack space for the mentioned example file. </p> <p> A diff of basic_xml_grammar.ipp follows. </p> <pre class="wiki">272c272 &lt; CharDataChars = *(anychar_p - chset_p(L"&amp;&lt;")); --- &gt; CharDataChars = +(anychar_p - chset_p(L"&amp;&lt;")); 308c308 &lt; | (Reference | CharData) &gt;&gt; content --- &gt; | +(Reference | CharData) &gt;&gt; L"&lt;" 371c371 &lt; &gt;&gt; CharData --- &gt; &gt;&gt; !CharData </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1498 Trac 1.4.3 Robert Ramey Sun, 23 Dec 2007 22:39:34 GMT status changed; resolution, milestone set https://svn.boost.org/trac10/ticket/1498#comment:1 https://svn.boost.org/trac10/ticket/1498#comment:1 <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">fixed</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">Boost 1.36.0</span> </li> </ul> <p> Very good call. </p> <p> I appreciate how much effort it is to track something like this down. </p> <p> I'm making the change and running the tests. </p> <p> RObert Ramey </p> Ticket