Boost C++ Libraries: Ticket #2970: Out of boundary access with STLport https://svn.boost.org/trac10/ticket/2970 <p> In lexical_cast.hpp, line 519, it is assumed that empty strings end with a null char, but this is not true with STLPort : </p> <p> <code>char last_grp_size = grouping[0] &lt;= 0 ? CHAR_MAX : grouping[0];</code> </p> <p> <code>grouping[0]</code> has an undefined value when <code>grouping</code> is empty. I propose this to fix it : </p> <p> <code>char last_grp_size = grouping_size == 0 || grouping[0] &lt;= 0 ? CHAR_MAX : grouping[0];</code> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2970 Trac 1.4.3 Ulrich Eckhardt Fri, 29 May 2009 06:27:02 GMT summary changed; cc set https://svn.boost.org/trac10/ticket/2970#comment:1 https://svn.boost.org/trac10/ticket/2970#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">Ulrich Eckhardt</span> added </li> <li><strong>summary</strong> <span class="trac-field-old">Out of boundary access with STLPort</span> → <span class="trac-field-new">Out of boundary access with STLport</span> </li> </ul> <p> The expression 's[s.size()]' is okay on a string, as long as 's' refers to a const string. Now, it would be interesting which version of STLport you have and how it behaves, i.e. how you detected a misbehaviour, because a missing zero would be a bug there. </p> <p> The code in question is this: </p> <pre class="wiki"> std::string const&amp; grouping = np.grouping(); [...] char last_grp_size = grouping[0] &lt;= 0 ? CHAR_MAX : grouping[0]; // a) Since grouping is const, grouping[grouping.size()] returns 0. </pre><p> Note especially the comment, which basically repeats what I wrote above. </p> Ticket anonymous Fri, 05 Jun 2009 09:08:11 GMT <link>https://svn.boost.org/trac10/ticket/2970#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2970#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2970#comment:1" title="Comment 1">eckhardt</a>: </p> <blockquote class="citation"> <p> The expression 's[s.size()]' is okay on a string, as long as 's' refers to a const string. Now, it would be interesting which version of STLport you have and how it behaves, i.e. how you detected a misbehaviour, because a missing zero would be a bug there. </p> </blockquote> <p> I didn't know this, do you have a reference explaining this? I have STLPort 5.0.0. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ulrich Eckhardt</dc:creator> <pubDate>Sat, 06 Jun 2009 06:27:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2970#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2970#comment:3</guid> <description> <p> There is pretty little explanation, but it is simply written in the C++ standard. I guess that this is a compromise made to help migration from char* strings, because there you could also access all elements from str<a class="missing changeset" title="No changeset 0 in the repository">[0]</a> to str[size] inclusive. </p> <p> Now, what I still don't know is what exactly you are seeing. Is STLport's debug mode throwing an out-of-bounds access or is something else failing? Can you provide some code that fails? </p> <p> Lastly, STLport 5.0.0 was released 2005-11-02! That's almost four years ago! Further, since I partially maintained the STLport port to MS Windows CE, I know that there is actually a test-case for the above behaviour, though I'm not sure when exactly the test was added and (possibly) the behaviour fixed. If I were you, I would consider upgrading, at least to the last 5.0 release. OTOH, current compilers usually come with a well-working C++ stdlib, so just using the native one would make things easier generally. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 18 Jun 2009 15:13:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2970#comment:4 https://svn.boost.org/trac10/ticket/2970#comment:4 <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> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2970#comment:3" title="Comment 3">eckhardt</a>: </p> <blockquote class="citation"> <p> Now, what I still don't know is what exactly you are seeing. Is STLport's debug mode throwing an out-of-bounds access or is something else failing? Can you provide some code that fails? </p> </blockquote> <p> In this code, when str is "1024", sometime it returned 1024, sometime 1 : </p> <p> <code>boost::lexical_cast&lt; unsigned &gt;( str );</code> </p> <p> The change I provided fixed that. </p> <blockquote class="citation"> <p> Lastly, STLport 5.0.0 was released 2005-11-02! That's almost four years ago! Further, since I partially maintained the STLport port to MS Windows CE, I know that there is actually a test-case for the above behaviour, though I'm not sure when exactly the test was added and (possibly) the behaviour fixed. If I were you, I would consider upgrading, at least to the last 5.0 release. OTOH, current compilers usually come with a well-working C++ stdlib, so just using the native one would make things easier generally. </p> </blockquote> <p> Probably we should upgrade STLPort. We are using STLPort in a cross-platform project, and on some platforms some features are not available with the C++ compiler. </p> Ticket