bpo-46841: Don't scan backwards in bytecode (GH-31901)

This commit is contained in:
Mark Shannon 2022-03-16 00:08:37 +00:00 committed by GitHub
parent a4674f0194
commit 49e1e1e1bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 15 deletions

View file

@ -359,9 +359,12 @@ _PyGen_yf(PyGenObject *gen)
assert(code[0] != SEND);
return NULL;
}
if (code[(frame->f_lasti-1)*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0)
int opcode = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)];
int oparg = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)+1];
if (opcode != RESUME || oparg < 2) {
/* Not in a yield from */
return NULL;
}
yf = _PyFrame_StackPeek(frame);
Py_INCREF(yf);
}