]> granicus.if.org Git - python/commitdiff
Issue #23321: Fixed a crash in str.decode() when error handler returned
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 25 Jan 2015 23:22:54 +0000 (01:22 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 25 Jan 2015 23:22:54 +0000 (01:22 +0200)
replacment string longer than mailformed input data.

Misc/NEWS
Objects/unicodeobject.c

index 9b68d3d55bd204b798ebd007e9a516914de2c251..4c4db0f9b0b25e11330add530bf8216a1084bc41 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,6 +11,9 @@ Release date: TBA
 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
index 216cd6a3e548add6936260071f001c93809d2835..84ab6a114cd3eefeef2b112cc36c880df900c315 100644 (file)
@@ -4190,9 +4190,13 @@ unicode_decode_call_errorhandler_writer(
     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;