Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check nplainlocals instead of totalargs.
  • Loading branch information
ericsnowcurrently committed May 26, 2021
commit e4387e416d35a97b8257ea629eea5f362b96cb18
17 changes: 8 additions & 9 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
return NULL;
}

if (argcount > nlocals || kwonlyargcount > nlocals) {
PyErr_SetString(PyExc_ValueError, "code: varnames is too small");
return NULL;
}
int totalargs = argcount +
kwonlyargcount +
((flags & CO_VARARGS) != 0) +
((flags & CO_VARKEYWORDS) != 0);
if (totalargs > nlocals) {
// Note that totalargs = nlocals - nplainlocals. We check nplainlocals
// here to avoid the possibility of overflow (however remote).
int nplainlocals = nlocals -
argcount -
kwonlyargcount -
((flags & CO_VARARGS) != 0) -
((flags & CO_VARKEYWORDS) != 0);
if (nplainlocals < 0) {
PyErr_SetString(PyExc_ValueError, "code: varnames is too small");
return NULL;
}
Expand Down