]> granicus.if.org Git - python/commitdiff
Issue #6922: Fix an infinite loop when trying to decode an invalid
authorGeorg Brandl <georg@python.org>
Thu, 17 Sep 2009 11:28:09 +0000 (11:28 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 17 Sep 2009 11:28:09 +0000 (11:28 +0000)
UTF-32 stream with a non-raising error handler like "replace" or "ignore".

Lib/test/test_codecs.py
Misc/NEWS
Objects/unicodeobject.c

index 06cab1c7efa0924e693b145a81988f6dbc611c7b..18933112a6ecfa0fb5274f5205d0d66a197c92cc 100644 (file)
@@ -305,6 +305,12 @@ class UTF32Test(ReadTest):
             ]
         )
 
+    def test_handlers(self):
+        self.assertEqual((u'\ufffd', 1),
+                         codecs.utf_32_decode('\x01', 'replace', True))
+        self.assertEqual((u'', 1),
+                         codecs.utf_32_decode('\x01', 'ignore', True))
+
     def test_errors(self):
         self.assertRaises(UnicodeDecodeError, codecs.utf_32_decode,
                           "\xff", "strict", True)
@@ -422,6 +428,12 @@ class UTF16Test(ReadTest):
             ]
         )
 
+    def test_handlers(self):
+        self.assertEqual((u'\ufffd', 1),
+                         codecs.utf_16_decode('\x01', 'replace', True))
+        self.assertEqual((u'', 1),
+                         codecs.utf_16_decode('\x01', 'ignore', True))
+
     def test_errors(self):
         self.assertRaises(UnicodeDecodeError, codecs.utf_16_decode, "\xff", "strict", True)
 
index 77969570475d777e6d45c99879603de038a98355..dc37a37dd2ec1da783def1479cf132e6dfee73b3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #6922: Fix an infinite loop when trying to decode an invalid
+  UTF-32 stream with a non-raising error handler like "replace" or "ignore".
+
 - Issue #6713: Improve performance of integer -> string conversions.
 
 - Issue #1590864: Fix potential deadlock when mixing threads and fork().
index c4b490295f32e14e7a0f8b5bba0888d9d1996be1..61645101171a140624eb0e8d6cd592f00797ad3e 100644 (file)
@@ -2321,7 +2321,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
         if (unicode_decode_call_errorhandler(
                 errors, &errorHandler,
                 "utf32", errmsg,
-                starts, size, &startinpos, &endinpos, &exc, &s,
+                starts, size, &startinpos, &endinpos, &exc, (const char **)&q,
                 &unicode, &outpos, &p))
             goto onError;
     }