Skip to content

Commit 3130f94

Browse files
committed
change co_stacksize upper limit
1 parent f8a0eef commit 3130f94

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Objects/codeobject.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,14 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
443443
* usually prevents crashes due to assertions but a MemoryError may still
444444
* be triggered later.
445445
*
446-
* See https://github.com/python/cpython/issues/126119 for details.
446+
* See https://github.com/python/cpython/issues/126119 for details
447+
* and corresponding PR for the rationale on the upper limit value.
447448
*/
448-
int ub = (int)(INT_MAX / sizeof(PyObject *)) - FRAME_SPECIALS_SIZE;
449+
Py_ssize_t limit = (Py_ssize_t)(INT_MAX / 16) - FRAME_SPECIALS_SIZE;
449450
Py_ssize_t nlocalsplus = PyTuple_GET_SIZE(con->localsplusnames);
450-
if (nlocalsplus >= (Py_ssize_t)ub || con->stacksize >= (int)ub - nlocalsplus) {
451-
PyErr_SetString(PyExc_OverflowError, "code: co_stacksize is too large");
451+
if (nlocalsplus >= limit || con->stacksize >= limit - nlocalsplus) {
452+
PyErr_SetString(PyExc_OverflowError,
453+
"code: locals + stack size is too large");
452454
return -1;
453455
}
454456
return 0;

0 commit comments

Comments
 (0)