mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-35552: Fix reading past the end in PyUnicode_FromFormat() and PyBytes_FromFormat(). (GH-11276)
Format characters "%s" and "%V" in PyUnicode_FromFormat() and "%s" in PyBytes_FromFormat() no longer read memory past the limit if precision is specified.
This commit is contained in:
parent
f1ec3cefad
commit
d586ccb04f
3 changed files with 21 additions and 6 deletions
|
@ -2578,9 +2578,15 @@ unicode_fromformat_write_cstr(_PyUnicodeWriter *writer, const char *str,
|
|||
PyObject *unicode;
|
||||
int res;
|
||||
|
||||
length = strlen(str);
|
||||
if (precision != -1)
|
||||
length = Py_MIN(length, precision);
|
||||
if (precision == -1) {
|
||||
length = strlen(str);
|
||||
}
|
||||
else {
|
||||
length = 0;
|
||||
while (length < precision && str[length]) {
|
||||
length++;
|
||||
}
|
||||
}
|
||||
unicode = PyUnicode_DecodeUTF8Stateful(str, length, "replace", NULL);
|
||||
if (unicode == NULL)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue