[Python-checkins] r74869 - in python/trunk: Lib/test/test_codecs.py Misc/NEWS Objects/unicodeobject.c

georg.brandl python-checkins at python.org
Thu Sep 17 13:28:09 CEST 2009


Author: georg.brandl
Date: Thu Sep 17 13:28:09 2009
New Revision: 74869
Log:
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".
Modified:
 python/trunk/Lib/test/test_codecs.py
 python/trunk/Misc/NEWS
 python/trunk/Objects/unicodeobject.c
Modified: python/trunk/Lib/test/test_codecs.py
==============================================================================
--- python/trunk/Lib/test/test_codecs.py	(original)
+++ python/trunk/Lib/test/test_codecs.py	Thu Sep 17 13:28:09 2009
@@ -305,6 +305,12 @@
 ]
 )
 
+ 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 @@
 ]
 )
 
+ 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)
 
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Sep 17 13:28:09 2009
@@ -12,6 +12,9 @@
 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().
Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Thu Sep 17 13:28:09 2009
@@ -2321,7 +2321,7 @@
 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;
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /