GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188)

This commit is contained in:
Pablo Galindo Salgado 2022-08-23 11:13:53 +01:00 committed by GitHub
parent ba7d4b9dc1
commit 16ebae4cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Fixed a bug that caused ``_PyCode_GetExtra`` to return garbage for negative
indexes. Patch by Pablo Galindo

View File

@ -1339,7 +1339,7 @@ _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
PyCodeObject *o = (PyCodeObject*) code;
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) o->co_extra;
if (co_extra == NULL || co_extra->ce_size <= index) {
if (co_extra == NULL || index < 0 || co_extra->ce_size <= index) {
*extra = NULL;
return 0;
}