summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-25 23:24:31 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-25 23:24:31 (GMT)
commitbbd3aa8ece3ed4caf98158086c4599248eb9cddf (patch)
treee6ffd1db181cb5e9a83c00f71ac60bbc4db3d4e6
parent07985ef387a87486a0e632844be03a8877e7f889 (diff)
parent7e4b9057b3180ed1b7b26dc8f9a2d2162d4e83b0 (diff)
downloadcpython-bbd3aa8ece3ed4caf98158086c4599248eb9cddf.zip
cpython-bbd3aa8ece3ed4caf98158086c4599248eb9cddf.tar.gz
cpython-bbd3aa8ece3ed4caf98158086c4599248eb9cddf.tar.bz2
Issue #23321: Fixed a crash in str.decode() when error handler returned
replacment string longer than mailformed input data.
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/unicodeobject.c8
2 files changed, 9 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 163aff4..3c08363 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,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 #22286: The "backslashreplace" error handlers now works with
decoding and translating.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ee0c044..03f795c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4155,9 +4155,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;