mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #16096: Fix several occurrences of potential signed integer overflow. Thanks Serhiy Storchaka.
This commit is contained in:
parent
a2028733ef
commit
c04ddff290
7 changed files with 30 additions and 35 deletions
|
@ -1265,14 +1265,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
|||
assert(ptoappend != NULL);
|
||||
assert(ntoappend > 0);
|
||||
while (usednew + ntoappend > totalnew) {
|
||||
size_t bigger = totalnew << 1;
|
||||
if ((bigger >> 1) != totalnew) { /* overflow */
|
||||
if (totalnew > (PY_SSIZE_T_MAX >> 1)) { /* overflow */
|
||||
PyErr_NoMemory();
|
||||
goto Done;
|
||||
}
|
||||
if (_PyBytes_Resize(&newfmt, bigger) < 0)
|
||||
totalnew <<= 1;
|
||||
if (_PyBytes_Resize(&newfmt, totalnew) < 0)
|
||||
goto Done;
|
||||
totalnew = bigger;
|
||||
pnew = PyBytes_AsString(newfmt) + usednew;
|
||||
}
|
||||
memcpy(pnew, ptoappend, ntoappend);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue