Restrict co_code to be under INT_MAX in codeobject (GH-20628)

This commit is contained in:
Ammar Askar 2020-06-10 23:31:22 +00:00 committed by GitHub
parent 1642c0ef75
commit 3b3b83c965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -397,9 +397,9 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
return -1;
}
int len = Py_SAFE_DOWNCAST(
PyBytes_GET_SIZE(f->f_code->co_code)/sizeof(_Py_CODEUNIT),
Py_ssize_t, int);
/* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this
* should never overflow. */
int len = (int)(PyBytes_GET_SIZE(f->f_code->co_code) / sizeof(_Py_CODEUNIT));
int *lines = marklines(f->f_code, len);
if (lines == NULL) {
return -1;