File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments