[1.48 lexical_cast] Illegal Derefence

Hi, This does an illegal dereference in boost\lexical_cast.hpp(1357): if ( Traits::eq(minus,*start) ) #include <boost/lexical_cast.hpp> #include <boost/range/iterator_range.hpp> int main() { boost::iterator_range<const char*> v; boost::lexical_cast<int>(v); } -- Olaf

2011/11/2 Olaf van der Spek <ml@vdspek.org>:
Hi,
This does an illegal dereference in boost\lexical_cast.hpp(1357): if ( Traits::eq(minus,*start) )
#include <boost/lexical_cast.hpp> #include <boost/range/iterator_range.hpp>
int main() { boost::iterator_range<const char*> v; boost::lexical_cast<int>(v); }
Thanks a lot for this bug report. I tried this code with 1.42 version (it failed with an assertion), trunk (sigfault), release/branch(sigfault) and with 1.46 (bad_lexical_cast exception). It is an old bug and if this bug is not critical for you, I think it can wait till next release (1.49). I`ll create a ticket with bug description. Best regards, Antony Polukhin

Fast solution will be: @@ -1144,6 +1144,7 @@ bool shl_input_streamable(InputStreamable& input) { std::basic_ostream<CharT> stream(&stringbuffer); + stream << '\0'; // Force stringbuffer initialization bool const result = !(stream << input).fail(); start = stringbuffer.pbase(); finish = stringbuffer.pptr(); This patch replaces Segmentation Fault with bad_lexical_cast exception. OK to merge to trunk? Best regards, Antony Polukhin

On Wed, Nov 2, 2011 at 5:44 PM, Antony Polukhin <antoshkka@gmail.com> wrote:
I tried this code with 1.42 version (it failed with an assertion), trunk (sigfault), release/branch(sigfault) and with 1.46 (bad_lexical_cast exception). It is an old bug and if this bug is not critical for you,
Is it? 1.46 and 1.47 work fine (bad_lexical_cast exception).
I think it can wait till next release (1.49).
Eh, why would you delay the fix? It seems like a serious issue. -- Olaf

2011/11/2 Olaf van der Spek <ml@vdspek.org>:
Eh, why would you delay the fix? It seems like a serious issue.
This patch fixes the bug in more portable way: @@ -1147,7 +1147,7 @@ bool const result = !(stream << input).fail(); start = stringbuffer.pbase(); finish = stringbuffer.pptr(); - return result; + return result && (start != finish); } template <class T> All lexical_cast tests successfully passed with this patch on clang-linux-2.9, gcc-4.4, gcc-4.5 and gcc-4.6. This patch replaces Segmentation Fault with bad_lexical_cast exception (tested on code provided by Olaf van der Spek). OK to merge to release branch? Best regards, Antony Polukhin

On Wed, Nov 2, 2011 at 2:00 PM, Antony Polukhin <antoshkka@gmail.com> wrote:
2011/11/2 Olaf van der Spek <ml@vdspek.org>:
Eh, why would you delay the fix? It seems like a serious issue.
This patch fixes the bug in more portable way:
@@ -1147,7 +1147,7 @@ bool const result = !(stream << input).fail(); start = stringbuffer.pbase(); finish = stringbuffer.pptr(); - return result; + return result && (start != finish); }
template <class T>
All lexical_cast tests successfully passed with this patch on clang-linux-2.9, gcc-4.4, gcc-4.5 and gcc-4.6. This patch replaces Segmentation Fault with bad_lexical_cast exception (tested on code provided by Olaf van der Spek).
OK to merge to release branch?
No. It needs to be applied to trunk, then given enough time to cycle through the trunk regression tests. Once that happens, and the tests are clear, then it might be appropriate to ask to merge to release. Also, is there going to be a regression test added to detect the problem in the future? --Beman

2011/11/5 Olaf van der Spek <ml@vdspek.org>:
Any updates?
Fix commited to trunk. New test case has been written (lexical_cast_empty_input_test). I`m now waiting for backtraces from darwin platform. Other platforms work well. But trunk version also contains patch for better performance of lexical_cast with Boost.Container. As it would be more clear with darwin platform issue, shall I merge both patches to release branch or only Invalid dereference patch? Patches do not interact. Best regards, Antony Polukhin

On Sat, Nov 5, 2011 at 7:11 AM, Antony Polukhin <antoshkka@gmail.com> wrote:
2011/11/5 Olaf van der Spek <ml@vdspek.org>:
Any updates?
Fix commited to trunk. New test case has been written (lexical_cast_empty_input_test). I`m now waiting for backtraces from darwin platform. Other platforms work well.
But trunk version also contains patch for better performance of lexical_cast with Boost.Container. As it would be more clear with darwin platform issue, shall I merge both patches to release branch or only Invalid dereference patch? Patches do not interact.
I think merge rules don't allow performance patches to be merged into release at this point in the release cycle. -- Olaf

Darwin platform failures are a Boost.Test library fault. OK to merge changeset https://svn.boost.org/trac/boost/changeset/75283 (including new test case) to release branch? Best regards, Antony Polukhin

On Sat, Nov 5, 2011 at 1:50 PM, Antony Polukhin <antoshkka@gmail.com> wrote:
Darwin platform failures are a Boost.Test library fault.
OK to merge changeset https://svn.boost.org/trac/boost/changeset/75283 (including new test case) to release branch?
Yes. Please do so right away. Sorry for the delay in responding.
participants (3)
-
Antony Polukhin
-
Beman Dawes
-
Olaf van der Spek