New submission from Serhiy Storchaka <>:

Based on discussion in PR 660.

_PyUnicodeWriter_Prepare() is used incorrectly in 
unicode_decode_call_errorhandler_writer(), _PyUnicode_DecodeUnicodeEscape() and 
PyUnicode_DecodeRawUnicodeEscape() in Objects/unicodeobject.c. The second 
argument is the number of characters that should be reserved after the current 
position. But in these places the total minimal size is passed to 
_PyUnicodeWriter_Prepare(). This can lead to allocating more memory than 

components: Interpreter Core, Unicode
messages: 312038
nosy: ezio.melotti, serhiy.storchaka, vstinner, xiang.zhang
priority: normal
severity: normal
status: open
title: Fix incorrect usage of _PyUnicodeWriter_Prepare()
type: resource usage
versions: Python 3.6, Python 3.7, Python 3.8

Python tracker <>
Python-bugs-list mailing list

Reply via email to