mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Sanitize reference management in the utf-8 encoder
This commit is contained in:
parent
f72d4ef327
commit
31b92a534f
1 changed files with 4 additions and 5 deletions
|
@ -4722,6 +4722,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
int kind;
|
int kind;
|
||||||
void *data;
|
void *data;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
|
PyObject *rep = NULL;
|
||||||
|
|
||||||
if (!PyUnicode_Check(unicode)) {
|
if (!PyUnicode_Check(unicode)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
|
@ -4774,7 +4775,6 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
*p++ = (char)(0x80 | (ch & 0x3f));
|
*p++ = (char)(0x80 | (ch & 0x3f));
|
||||||
} else if (0xD800 <= ch && ch <= 0xDFFF) {
|
} else if (0xD800 <= ch && ch <= 0xDFFF) {
|
||||||
Py_ssize_t newpos;
|
Py_ssize_t newpos;
|
||||||
PyObject *rep;
|
|
||||||
Py_ssize_t repsize, k, startpos;
|
Py_ssize_t repsize, k, startpos;
|
||||||
startpos = i-1;
|
startpos = i-1;
|
||||||
rep = unicode_encode_call_errorhandler(
|
rep = unicode_encode_call_errorhandler(
|
||||||
|
@ -4822,10 +4822,8 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
enum PyUnicode_Kind repkind;
|
enum PyUnicode_Kind repkind;
|
||||||
void *repdata;
|
void *repdata;
|
||||||
|
|
||||||
if (PyUnicode_READY(rep) < 0) {
|
if (PyUnicode_READY(rep) < 0)
|
||||||
Py_DECREF(rep);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
repkind = PyUnicode_KIND(rep);
|
repkind = PyUnicode_KIND(rep);
|
||||||
repdata = PyUnicode_DATA(rep);
|
repdata = PyUnicode_DATA(rep);
|
||||||
|
|
||||||
|
@ -4841,7 +4839,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
*p++ = (char)c;
|
*p++ = (char)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_DECREF(rep);
|
Py_CLEAR(rep);
|
||||||
} else if (ch < 0x10000) {
|
} else if (ch < 0x10000) {
|
||||||
*p++ = (char)(0xe0 | (ch >> 12));
|
*p++ = (char)(0xe0 | (ch >> 12));
|
||||||
*p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
|
*p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
|
||||||
|
@ -4872,6 +4870,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
return result;
|
return result;
|
||||||
error:
|
error:
|
||||||
|
Py_XDECREF(rep);
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
Py_XDECREF(result);
|
Py_XDECREF(result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue