From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 13 Feb 2018 09:32:46 +0000 (-0800) Subject: bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors handler. (GH... X-Git-Tag: v3.6.5rc1~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=310b424c476e3de3370990e5b9a10acc64ed17f8;p=python bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors handler. (GH-5636) (cherry picked from commit b7e2d67f7c035f09c921ca4e7a36529cd502ccf7) Co-authored-by: Serhiy Storchaka --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a246756d94..bed7d419b0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4500,7 +4500,7 @@ unicode_decode_call_errorhandler_writer( } if (need_to_grow) { writer->overallocate = 1; - if (_PyUnicodeWriter_Prepare(writer, writer->min_length, + if (_PyUnicodeWriter_Prepare(writer, writer->min_length - writer->pos, PyUnicode_MAX_CHAR_VALUE(repunicode)) == -1) goto onError; } @@ -6176,9 +6176,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s, &writer)) { goto onError; } - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) { - goto onError; - } + assert(end - s <= writer.size - writer.pos); #undef WRITE_ASCII_CHAR #undef WRITE_CHAR @@ -6455,9 +6453,7 @@ PyUnicode_DecodeRawUnicodeEscape(const char *s, &writer)) { goto onError; } - if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) { - goto onError; - } + assert(end - s <= writer.size - writer.pos); #undef WRITE_CHAR }