Skip to content

Commit 27950d8

Browse files
GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188)
(cherry picked from commit 16ebae4) Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 04e3785 commit 27950d8

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
@@ -1337,7 +1337,7 @@ _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
13371337
PyCodeObject *o = (PyCodeObject*) code;
13381338
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) o->co_extra;
13391339

1340-
if (co_extra == NULL || co_extra->ce_size <= index) {
1340+
if (co_extra == NULL || index < 0 || co_extra->ce_size <= index) {
13411341
*extra = NULL;
13421342
return 0;
13431343
}

0 commit comments

Comments
 (0)