[Python-checkins] cpython (3.4): Issue #23321: Fixed a crash in str.decode() when error handler returned

serhiy.storchaka python-checkins at python.org
Mon Jan 26 00:27:42 CET 2015


https://hg.python.org/cpython/rev/2de90090e486
changeset:   94277:2de90090e486
branch:      3.4
parent:      94272:3a9b1e5fe179
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Jan 26 01:22:54 2015 +0200
summary:
  Issue #23321: Fixed a crash in str.decode() when error handler returned
replacment string longer than mailformed input data.

files:
  Misc/NEWS               |  3 +++
  Objects/unicodeobject.c |  8 ++++++--
  2 files changed, 9 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,6 +11,9 @@
 Core and Builtins
 -----------------
 
+- Issue #23321: Fixed a crash in str.decode() when error handler returned
+  replacment string longer than mailformed input data.
+
 - Issue #23048: Fix jumping out of an infinite while loop in the pdb.
 
 - Issue #20335: bytes constructor now raises TypeError when encoding or errors
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4190,9 +4190,13 @@
     if (PyUnicode_READY(repunicode) < 0)
         goto onError;
     replen = PyUnicode_GET_LENGTH(repunicode);
-    writer->min_length += replen;
-    if (replen > 1)
+    if (replen > 1) {
+        writer->min_length += replen - 1;
         writer->overallocate = 1;
+        if (_PyUnicodeWriter_Prepare(writer, writer->min_length,
+                            PyUnicode_MAX_CHAR_VALUE(repunicode)) == -1)
+            goto onError;
+    }
     if (_PyUnicodeWriter_WriteStr(writer, repunicode) == -1)
         goto onError;
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list