mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
#6373: SystemError in str.encode('latin1', 'surrogateescape')
if the string contains unpaired surrogates. (In debug build, crash in assert()) This can happen with normal processing, if python starts with utf-8, then calls sys.setfilesystemencoding('latin-1')
This commit is contained in:
parent
f909202c11
commit
84ec8d9314
3 changed files with 11 additions and 0 deletions
|
@ -4201,10 +4201,12 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
|
|||
repsize = PyBytes_Size(repunicode);
|
||||
if (repsize > 1) {
|
||||
/* Make room for all additional bytes. */
|
||||
respos = str - PyBytes_AS_STRING(res);
|
||||
if (_PyBytes_Resize(&res, ressize+repsize-1)) {
|
||||
Py_DECREF(repunicode);
|
||||
goto onError;
|
||||
}
|
||||
str = PyBytes_AS_STRING(res) + respos;
|
||||
ressize += repsize-1;
|
||||
}
|
||||
memcpy(str, PyBytes_AsString(repunicode), repsize);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue