Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make sure that the Executor objects in the COLD_EXITS array aren't assumed
to be GC-able (which would access bytes outside the object).
10 changes: 10 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ executor_traverse(PyObject *o, visitproc visit, void *arg)
return 0;
}

static int
executor_is_gc(PyObject *o)
{
if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[COLD_EXIT_COUNT]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undefined behavior in C. Although it will mostly work in practice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I take it this should work?

Suggested change
if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[COLD_EXIT_COUNT]) {
if (_Py_IsImmortal(o)) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a similar thing to the top of executor_traverse()? (Although, really, cold exits don't have exits, so their exit_count should always be zero, right? So why bother.

Anyway, see gh-118182 for a fix.

return 0;
}
return 1;
}

PyTypeObject _PyUOpExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_executor",
Expand All @@ -405,6 +414,7 @@ PyTypeObject _PyUOpExecutor_Type = {
.tp_methods = executor_methods,
.tp_traverse = executor_traverse,
.tp_clear = executor_clear,
.tp_is_gc = executor_is_gc,
};

/* TO DO -- Generate these tables */
Expand Down