Title: Assertion failure when func_repr is called on an already tp_clear-ed object · Issue #91636 · python/cpython · GitHub
Open Graph Title: Assertion failure when func_repr is called on an already tp_clear-ed object · Issue #91636 · python/cpython
X Title: Assertion failure when func_repr is called on an already tp_clear-ed object · Issue #91636 · python/cpython
Description: Crash report It is possible to resurrect a tp_clear-ed object using pure python. The following piece of code illustrates how: import gc, weakref class LateFin: __slots__ = ('ref',) def __del__(self): # 8. Now `latefin`'s finalizer is cal...
Open Graph Description: Crash report It is possible to resurrect a tp_clear-ed object using pure python. The following piece of code illustrates how: import gc, weakref class LateFin: __slots__ = ('ref',) def __del__(self...
X Description: Crash report It is possible to resurrect a tp_clear-ed object using pure python. The following piece of code illustrates how: import gc, weakref class LateFin: __slots__ = ('ref',) def __de...
Opengraph URL: https://github.com/python/cpython/issues/91636
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Assertion failure when func_repr is called on an already tp_clear-ed object","articleBody":"\u003c!--\n Use this template for hard crashes of the interpreter, segmentation faults, failed C-level assertions, and similar.\n Do not submit this form if you encounter an exception being unexpectedly raised from a Python function.\n Most of the time, these should be filed as bugs, rather than crashes.\n\n The CPython interpreter is itself written in a different programming language, C.\n For CPython, a \"crash\" is when Python itself fails, leading to a traceback in the C stack.\n--\u003e\n\n**Crash report**\n\nIt is possible to resurrect a `tp_clear`-ed object using pure python. The following piece of code illustrates how:\n\n```python\nimport gc, weakref\n\n\nclass LateFin:\n __slots__ = ('ref',)\n\n def __del__(self):\n # 8. Now `latefin`'s finalizer is called. Here we obtain a reference to\n # `func`, which is currently undergoing `tp_clear`.\n global func\n func = self.ref()\n\n\nclass Cyclic(tuple):\n __slots__ = ()\n\n # 4. The finalizers of all garbage objects are called. In this case this is\n # only us as `func` doesn't have a finalizer.\n def __del__(self):\n # 5. Create a weakref to `func` now. If we had created it earlier, it\n # would have been cleared by the garbage collector before calling the\n # finalizers.\n self[1].ref = weakref.ref(self[0])\n # 6. Drop the global reference to `latefin`. The only remaining\n # reference is the one we have.\n global latefin\n del latefin\n # 7. Now `func` is `tp_clear`-ed. This drops the last reference to `Cyclic`,\n # which gets `tp_dealloc`-ed. This drops the last reference to `latefin`.\n\n\nlatefin = LateFin()\nfunc = lambda: None\ncyc = tuple.__new__(Cyclic, (func, latefin))\n\n# 1. Create a reference cycle of `cyc` and `func`.\nfunc.__module__ = cyc\n\n# 2. Make the cycle unreachable, but keep the global reference to `latefin` so\n# that it isn't detected as garbage. This way its finalizer will not be called\n# immediately.\ndel func, cyc\n\n# 3. Invoke garbage collection, which will find `cyc` and `func` as garbage.\ngc.set_debug(gc.DEBUG_COLLECTABLE)\ngc.collect()\ngc.set_debug(0)\n\n# 9. Call `repr()`, which will try to use the NULL `func_qualname`.\nrepr(func)\n```\n\n```\n#5 0x00007ffff7d0a596 in __GI___assert_fail (assertion=assertion@entry=0x697e93 \"obj \u0026\u0026 _PyUnicode_CHECK(obj)\", file=file@entry=0x696a92 \"Objects/unicodeobject.c\", line=line@entry=3000, \n function=function@entry=0x69e110 \u003c__PRETTY_FUNCTION__.299\u003e \"unicode_fromformat_arg\") at assert.c:101\n#6 0x0000000000538d8e in unicode_fromformat_arg (writer=writer@entry=0x7fffffffd9f0, f=0x682bf1 \"U at %p\u003e\", f@entry=0x682bf0 \"%U at %p\u003e\", vargs=vargs@entry=0x7fffffffda28)\n at Objects/unicodeobject.c:3000\n#7 0x0000000000539098 in PyUnicode_FromFormatV (format=\u003coptimized out\u003e, vargs=vargs@entry=0x7fffffffda68) at Objects/unicodeobject.c:3109\n#8 0x00000000005391ab in PyUnicode_FromFormat (format=format@entry=0x682be6 \"\u003cfunction %U at %p\u003e\") at Objects/unicodeobject.c:3161\n#9 0x00000000004c2c7b in func_repr (op=\u003coptimized out\u003e) at Objects/funcobject.c:710\n#10 0x00000000004ea437 in PyObject_Repr (v=0x91d650) at Objects/object.c:434\n#11 0x0000000000571932 in builtin_repr (module=\u003coptimized out\u003e, obj=\u003coptimized out\u003e) at Python/bltinmodule.c:2252\n#12 0x00000000004e6c82 in cfunction_vectorcall_O (func=0x9a10f0, args=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/methodobject.c:514\n#13 0x00000000004a5700 in _PyObject_VectorcallTstate (tstate=0x915430 \u003c_PyRuntime+166000\u003e, callable=callable@entry=0x9a10f0, args=args@entry=0x9a4f98, nargsf=9223372036854775809, \n kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:92\n#14 0x00000000004a57cb in PyObject_Vectorcall (callable=callable@entry=0x9a10f0, args=args@entry=0x9a4f98, nargsf=\u003coptimized out\u003e, kwnames=kwnames@entry=0x0) at Objects/call.c:299\n#15 0x0000000000586b4b in _PyEval_EvalFrameDefault (tstate=0x915430 \u003c_PyRuntime+166000\u003e, frame=0x9a4f40, throwflag=\u003coptimized out\u003e) at Python/ceval.c:4765\n#16 0x000000000058af91 in _PyEval_EvalFrame (tstate=tstate@entry=0x915430 \u003c_PyRuntime+166000\u003e, frame=frame@entry=0x9a4f40, throwflag=throwflag@entry=0)\n at ./Include/internal/pycore_ceval.h:66\n#17 0x000000000058b09c in _PyEval_Vector (tstate=tstate@entry=0x915430 \u003c_PyRuntime+166000\u003e, func=func@entry=0xa41dd0, locals=locals@entry=0xa5ca80, args=args@entry=0x0, \n argcount=argcount@entry=0, kwnames=kwnames@entry=0x0) at Python/ceval.c:6387\n#18 0x000000000058b190 in PyEval_EvalCode (co=co@entry=0xaa0e70, globals=globals@entry=0xa5ca80, locals=locals@entry=0xa5ca80) at Python/ceval.c:1157\n#19 0x00000000005cb444 in run_eval_code_obj (tstate=tstate@entry=0x915430 \u003c_PyRuntime+166000\u003e, co=co@entry=0xaa0e70, globals=globals@entry=0xa5ca80, locals=locals@entry=0xa5ca80)\n at Python/pythonrun.c:1713\n#20 0x00000000005cb4fb in run_mod (mod=mod@entry=0xaafda0, filename=filename@entry=0xa8dad0, globals=globals@entry=0xa5ca80, locals=locals@entry=0xa5ca80, flags=flags@entry=0x7fffffffdf08, \n arena=arena@entry=0xa8dc20) at Python/pythonrun.c:1734\n#21 0x00000000005cb5bf in pyrun_file (fp=fp@entry=0x9c8d20, filename=filename@entry=0xa8dad0, start=start@entry=257, globals=globals@entry=0xa5ca80, locals=locals@entry=0xa5ca80, \n closeit=closeit@entry=1, flags=0x7fffffffdf08) at Python/pythonrun.c:1629\n#22 0x00000000005cded0 in _PyRun_SimpleFileObject (fp=fp@entry=0x9c8d20, filename=filename@entry=0xa8dad0, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffdf08)\n at Python/pythonrun.c:439\n#23 0x00000000005ce078 in _PyRun_AnyFileObject (fp=fp@entry=0x9c8d20, filename=filename@entry=0xa8dad0, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffdf08) at Python/pythonrun.c:78\n#24 0x00000000005e9d4b in pymain_run_file_obj (program_name=program_name@entry=0xa02210, filename=filename@entry=0xa8dad0, skip_source_first_line=0) at Modules/main.c:353\n#25 0x00000000005e9e49 in pymain_run_file (config=config@entry=0x8fb490 \u003c_PyRuntime+59600\u003e) at Modules/main.c:372\n#26 0x00000000005ea4e8 in pymain_run_python (exitcode=exitcode@entry=0x7fffffffe05c) at Modules/main.c:592\n#27 0x00000000005ea735 in Py_RunMain () at Modules/main.c:671\n#28 0x00000000005ea78a in pymain_main (args=args@entry=0x7fffffffe0a0) at Modules/main.c:701\n#29 0x00000000005ea80f in Py_BytesMain (argc=\u003coptimized out\u003e, argv=\u003coptimized out\u003e) at Modules/main.c:725\n#30 0x000000000041d70f in main (argc=\u003coptimized out\u003e, argv=\u003coptimized out\u003e) at ./Programs/python.c:15\n```\n\n**Your environment**\n\n- CPython versions tested on: 3.10.4, 3.11.0a7+\n- Operating system and architecture: x86_64\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-136401\n* gh-141993\n* gh-142152\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/hvenev","@type":"Person","name":"hvenev"},"datePublished":"2022-04-17T15:50:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/91636/cpython/issues/91636"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8f45a310-1872-278a-5666-d10da9184c16 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A524:1D772C:1ACB28B:2385398:696AF707 |
| html-safe-nonce | 2e0a08ae8e05f00731c25b432fa558cb56192877b8dbbfaa8fc24e04024a6de5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTI0OjFENzcyQzoxQUNCMjhCOjIzODUzOTg6Njk2QUY3MDciLCJ2aXNpdG9yX2lkIjoiMjg5MjY1Njc0NzU5MzAwNDgwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 447c8cc08bcb6d8b8d484ab31b66146bbc01e91d0fe2abf7dad3fd20b1031f0c |
| hovercard-subject-tag | issue:1206414586 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/91636/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8e8d3820afb53b4e18f02d37a0a0258b2ec133aedd8564c15aa5d62ebb369c4c/python/cpython/issues/91636 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8e8d3820afb53b4e18f02d37a0a0258b2ec133aedd8564c15aa5d62ebb369c4c/python/cpython/issues/91636 |
| og:image:alt | Crash report It is possible to resurrect a tp_clear-ed object using pure python. The following piece of code illustrates how: import gc, weakref class LateFin: __slots__ = ('ref',) def __del__(self... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hvenev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width