Skip to content

Crash with PYTHON_LLTRACE=4 due to presence of PyDictKeysObject on stack #129432

@markshannon

Description

@markshannon

Bug report

Bug description:

The dump_stack() function, used when tracing micro-op execution, crashes if a PyDictKeysObject* pointer is on the stack.
Despite the name, PyDictKeysObject is not a PyObject.

Introduced in f978fb4

I think the best fix would be arrange the fields (at least in the debug build) of PyDictKeysObject such that the dk_kind field is placed in the least significant byte of the ob_type field of PyObject and change DictKeysKind so that none of its values have the low 2 bits set to 0.
Then dump_stack can check the low bits of the ob_type to see whether the "object" is a PyObject or a PyDictKeysObject.

Looking forward, we expect to have an unused value for the low bits in PyStackRef, so we could assign them the meaning "not a Python object".
This would add overhead when pushing and popping PyDictKeysObjects, but would make introspection a lot more robust.

@mpage

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions