Skip to content

Crash when detaching dict from inline values and no memory is available#124547

@DinoV

Description

@DinoV

Bug report

Bug description:

Add to test_class.py in TestInlineValues:

deftest_detach_materialized_dict_no_memory(self): a=WithAttrs() d=a.__dict___testcapi.set_nomemory(0) delaprint(d["a"])

This will crash because the dictionary will no longer points to valid memory:

#0 Py_XINCREF (op=<unknown at remote 0xdddddddddddddddd>) at ./Include/refcount.h:456 #1 _Py_XNewRef (obj=<unknown at remote 0xdddddddddddddddd>) at ./Include/refcount.h:488 #2 _Py_dict_lookup_threadsafe (mp=mp@entry=0x7ffff778ff50, key=key@entry='a', hash=<optimized out>, value_addr=value_addr@entry=0x7fffffffb078) at Objects/dictobject.c:1544 #3 0x0000000000518457 in dict_subscript (self={'b': <unknown at remote 0xdddddddddddddddd>, 'd': <unknown at remote 0xdddddddddddddddd>, 'a': <unknown at remote 0xdddddddddddddddd>, 'c': <unknown at remote 0xdddddddddddddddd>}, key='a') at Objects/dictobject.c:3325 #4 0x000000000049d8c6 in PyObject_GetItem (o=o@entry={'b': <unknown at remote 0xdddddddddddddddd>, 'd': <unknown at remote 0xdddddddddddddddd>, 'a': <unknown at remote 0xdddddddddddddddd>, 'c': <unknown at remote 0xdddddddddddddddd>}, key=key@entry='a') at Objects/abstract.c:158 

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions