mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Merge in release25-maint r60793:
Added checks for integer overflows, contributed by Google. Some are only available if asserts are left in the code, in cases where they can't be triggered from Python code.
This commit is contained in:
parent
73baefd7fc
commit
9d53457e59
24 changed files with 438 additions and 54 deletions
|
|
@ -578,7 +578,7 @@ strop_expandtabs(PyObject *self, PyObject *args)
|
|||
char* e;
|
||||
char* p;
|
||||
char* q;
|
||||
Py_ssize_t i, j;
|
||||
Py_ssize_t i, j, old_j;
|
||||
PyObject* out;
|
||||
char* string;
|
||||
Py_ssize_t stringlen;
|
||||
|
|
@ -595,12 +595,18 @@ strop_expandtabs(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
/* First pass: determine size of output string */
|
||||
i = j = 0; /* j: current column; i: total of previous lines */
|
||||
i = j = old_j = 0; /* j: current column; i: total of previous lines */
|
||||
e = string + stringlen;
|
||||
for (p = string; p < e; p++) {
|
||||
if (*p == '\t')
|
||||
if (*p == '\t') {
|
||||
j += tabsize - (j%tabsize);
|
||||
else {
|
||||
if (old_j > j) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"new string is too long");
|
||||
return NULL;
|
||||
}
|
||||
old_j = j;
|
||||
} else {
|
||||
j++;
|
||||
if (*p == '\n') {
|
||||
i += j;
|
||||
|
|
@ -609,6 +615,11 @@ strop_expandtabs(PyObject *self, PyObject *args)
|
|||
}
|
||||
}
|
||||
|
||||
if ((i + j) < 0) {
|
||||
PyErr_SetString(PyExc_OverflowError, "new string is too long");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Second pass: create output string and fill it */
|
||||
out = PyString_FromStringAndSize(NULL, i+j);
|
||||
if (out == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue