Skip to content

Commit 16ebae4

Browse files
authored
GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188)
1 parent ba7d4b9 commit 16ebae4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a bug that caused ``_PyCode_GetExtra`` to return garbage for negative
2+
indexes. Patch by Pablo Galindo

Objects/codeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
13391339
PyCodeObject *o = (PyCodeObject*) code;
13401340
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) o->co_extra;
13411341

1342-
if (co_extra == NULL || co_extra->ce_size <= index) {
1342+
if (co_extra == NULL || index < 0 || co_extra->ce_size <= index) {
13431343
*extra = NULL;
13441344
return 0;
13451345
}

0 commit comments

Comments
 (0)