Skip to content

gc.get_referrers() can be used to see objects before they are fully built #101855

Description

@sigdevel

Crash report

That the problem is occurring in the Py_INCREF macro, it looks like that the error occurs because the code is trying to increment the reference count of an object that doesnt exist.

Steps to reproduce the behavior:
1.create a sample file that contains:

importgcdefg():
marker=object()
yieldmarker
[tup] = [xforxingc.get_referrers(marker) iftype(x) istuple]
print(tup)
print(tup[1])
tuple(g())
  1. just run without opt:
./target/python/Python-3.11.1/builded/bin/python3.11 ./target/python/founded/sig11_sync_Python3111_52.py

Error messages

stderr:

(<object object at 0x7f9e66d10160>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>)
Segmentation fault (core dumped)

gdb:

After run with synthetical sample, binary file aborted with Segfault:

Program terminated with signal SIGSEGV, Segmentation fault.
#0 Py_INCREF (op=0x0) at ./Include/object.h:502
warning: Source file is more recent than executable.
502	#ifdef Py_REF_DEBUG

Expected behavior

No assertion failed.

Additional context

For solution this problem added additional checking to ensure that the op argument is not a null pointer before trying to increment its reference count.

if (op==NULL) {
return;
}

(also added in a patch)

Environment

  • Tested on: Python 3.11.1
  • Operating system and architecture: Centos-based system (RED OS release MUROM (7.3.2)) ; 5.15.78-2.el7.3.x86_64

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions