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

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


https://hg.python.org/cpython/rev/1cd68b3c46aa
changeset:   94278:1cd68b3c46aa
parent:      94276:dd8a03e98158
parent:      94277:2de90090e486
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Jan 26 01:24:31 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
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #23321: Fixed a crash in str.decode() when error handler returned
+  replacment string longer than mailformed input data.
+
 - Issue #22286: The "backslashreplace" error handlers now works with
   decoding and translating.
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4155,9 +4155,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