]> granicus.if.org Git - python/commitdiff
Merged revisions 74869 via svnmerge from
authorGeorg Brandl <georg@python.org>
Thu, 17 Sep 2009 11:33:31 +0000 (11:33 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 17 Sep 2009 11:33:31 +0000 (11:33 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74869 | georg.brandl | 2009-09-17 13:28:09 +0200 (Do, 17 Sep 2009) | 4 lines

  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".
........

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

index cee819ca0af0c1fbaa281023add45f7363451ff2..57420ffb3b800e8522354f0c825cd020709f76f6 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 56d6d395d3908fa462921092ee981b471fae3863..3326bd94b0746440da2e50a45cba02495e970f9d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6.3
 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 #1590864: Fix potential deadlock when mixing threads and fork().
 
 - Issue #6844: Do not emit DeprecationWarnings when accessing a "message"
index e4f27e6762c227220c53bb0540362a6bf0db54f2..dbb2b4900f41fcc88296bab38964fc573007b802 100644 (file)
@@ -2207,7 +2207,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;
     }