Skip to content

Commit 7e4b905

Browse files
Issue #23321: Fixed a crash in str.decode() when error handler returned
replacment string longer than mailformed input data.
1 parent 1923b62 commit 7e4b905

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Release date: TBA
1111
Core and Builtins
1212
-----------------
1313

14+
- Issue #23321: Fixed a crash in str.decode() when error handler returned
15+
replacment string longer than mailformed input data.
16+
1417
- Issue #23048: Fix jumping out of an infinite while loop in the pdb.
1518

1619
- Issue #20335: bytes constructor now raises TypeError when encoding or errors

Objects/unicodeobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,9 +4190,13 @@ unicode_decode_call_errorhandler_writer(
41904190
if (PyUnicode_READY(repunicode) < 0)
41914191
goto onError;
41924192
replen = PyUnicode_GET_LENGTH(repunicode);
4193-
writer->min_length += replen;
4194-
if (replen > 1)
4193+
if (replen > 1) {
4194+
writer->min_length += replen - 1;
41954195
writer->overallocate = 1;
4196+
if (_PyUnicodeWriter_Prepare(writer, writer->min_length,
4197+
PyUnicode_MAX_CHAR_VALUE(repunicode)) == -1)
4198+
goto onError;
4199+
}
41964200
if (_PyUnicodeWriter_WriteStr(writer, repunicode) == -1)
41974201
goto onError;
41984202

0 commit comments

Comments
 (0)