[pypy-svn] r75719 - in pypy/branch/interplevel-codecs/pypy/module/_codecs: . test

afa at codespeak.net afa at codespeak.net
Thu Jul 1 16:27:23 CEST 2010


Author: afa
Date: Thu Jul  1 16:27:21 2010
New Revision: 75719

Modified:
   pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
Avoid buffer overrun in append_slice(); Test and fix.


Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py	Thu Jul  1 16:27:21 2010
@@ -232,10 +232,11 @@
             else:
                 builder.append(u"\\x")
                 zeros = 2
-            nb = zeros + 2 - len(num) # num starts with '0x'
+            lnum = len(num)
+            nb = zeros + 2 - lnum # num starts with '0x'
             if nb > 0:
                 builder.append_multiple_char(u'0', nb)
-            builder.append_slice(unicode(num), 2, 8)
+            builder.append_slice(unicode(num), 2, lnum)
             pos += 1
         return space.newtuple([space.wrap(builder.build()), w_end])
     else:

Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py	Thu Jul  1 16:27:21 2010
@@ -460,6 +460,9 @@
         assert '\xff'.decode('utf-7', 'ignore') == ''
         assert '\x00'.decode('unicode-internal', 'ignore') == ''
 
+    def test_backslahreplace(self):
+        assert u'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') == 'a\\xac\u1234\u20ac\u8000'
+
     def test_badhandler(self):
         import codecs
         results = ( 42, u"foo", (1,2,3), (u"foo", 1, 3), (u"foo", None), (u"foo",), ("foo", 1, 3), ("foo", None), ("foo",) )



More information about the Pypy-commit mailing list