Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81590 - in trunk: boost/locale libs/locale/test
From: artyomtnk_at_[hidden]
Date: 2012-11-27 11:05:54


Author: artyom
Date: 2012-11-27 11:05:54 EST (Tue, 27 Nov 2012)
New Revision: 81590
URL: http://svn.boost.org/trac/boost/changeset/81590

Log:
Fixed bug #7743 invalid encoding asccepted as valid

Text files modified:
   trunk/boost/locale/utf.hpp | 6 ++++++
   trunk/libs/locale/test/test_codepage_converter.cpp | 14 ++++++++++++++
   2 files changed, 20 insertions(+), 0 deletions(-)

Modified: trunk/boost/locale/utf.hpp
==============================================================================
--- trunk/boost/locale/utf.hpp (original)
+++ trunk/boost/locale/utf.hpp 2012-11-27 11:05:54 EST (Tue, 27 Nov 2012)
@@ -219,16 +219,22 @@
                 if(BOOST_LOCALE_UNLIKELY(p==e))
                     return incomplete;
                 tmp = *p++;
+ if (!is_trail(tmp))
+ return illegal;
                 c = (c << 6) | ( tmp & 0x3F);
             case 2:
                 if(BOOST_LOCALE_UNLIKELY(p==e))
                     return incomplete;
                 tmp = *p++;
+ if (!is_trail(tmp))
+ return illegal;
                 c = (c << 6) | ( tmp & 0x3F);
             case 1:
                 if(BOOST_LOCALE_UNLIKELY(p==e))
                     return incomplete;
                 tmp = *p++;
+ if (!is_trail(tmp))
+ return illegal;
                 c = (c << 6) | ( tmp & 0x3F);
             }
 

Modified: trunk/libs/locale/test/test_codepage_converter.cpp
==============================================================================
--- trunk/libs/locale/test/test_codepage_converter.cpp (original)
+++ trunk/libs/locale/test/test_codepage_converter.cpp 2012-11-27 11:05:54 EST (Tue, 27 Nov 2012)
@@ -140,6 +140,20 @@
         TEST_TO("\xf8\x90\x80\x80\x80",illegal); // 400 0000
         TEST_TO("\xfd\xbf\xbf\xbf\xbf\xbf",illegal); // 7fff ffff
 
+ std::cout << "-- Invalid trail" << std::endl;
+ TEST_TO("\xC2\x7F",illegal);
+ TEST_TO("\xdf\x7F",illegal);
+ TEST_TO("\xe0\x7F\x80",illegal);
+ TEST_TO("\xef\xbf\x7F",illegal);
+ TEST_TO("\xe0\x7F\x80",illegal);
+ TEST_TO("\xef\xbf\x7F",illegal);
+ TEST_TO("\xf0\x7F\x80\x80",illegal);
+ TEST_TO("\xf4\x7f\xbf\xbf",illegal);
+ TEST_TO("\xf0\x90\x7F\x80",illegal);
+ TEST_TO("\xf4\x8f\x7F\xbf",illegal);
+ TEST_TO("\xf0\x90\x80\x7F",illegal);
+ TEST_TO("\xf4\x8f\xbf\x7F",illegal);
+
         std::cout << "-- Invalid length" << std::endl;
 
         /// Test that this actually works


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk