Title: Null pointer dereference in `_tkinter` `AsObj` via re-entrant `__str__` · Issue #143310 · python/cpython · GitHub
Open Graph Title: Null pointer dereference in `_tkinter` `AsObj` via re-entrant `__str__` · Issue #143310 · python/cpython
X Title: Null pointer dereference in `_tkinter` `AsObj` via re-entrant `__str__` · Issue #143310 · python/cpython
Description: What happened? Passing a list that contains an object whose __str__ clears the list lets _tkinter’s AsObj recurse through PyObject_Str, which mutates the list while the outer loop still walks it. The subsequent PySequence_Fast_GET_ITEM h...
Open Graph Description: What happened? Passing a list that contains an object whose __str__ clears the list lets _tkinter’s AsObj recurse through PyObject_Str, which mutates the list while the outer loop still walks it. T...
X Description: What happened? Passing a list that contains an object whose __str__ clears the list lets _tkinter’s AsObj recurse through PyObject_Str, which mutates the list while the outer loop still walks it. T...
Opengraph URL: https://github.com/python/cpython/issues/143310
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Null pointer dereference in `_tkinter` `AsObj` via re-entrant `__str__`","articleBody":"### What happened?\n\nPassing a list that contains an object whose `__str__` clears the list lets `_tkinter`’s `AsObj` recurse through `PyObject_Str`, which mutates the list while the outer loop still walks it. The subsequent `PySequence_Fast_GET_ITEM` hits a NULL slot and crashes the interpreter.\n\n**Proof of Concept:**\n```python\nimport tkinter\n\ninterp = tkinter.Tcl()\n\nvictim = []\n\nclass Evil:\n def __str__(self):\n victim.clear()\n return \"boom\"\n\nvictim[:] = [Evil(), \"pad\"]\ninterp.call('set', 'var', victim)\n```\n\n\n**Affected Versions**\n\n\u003cdetails>\n\n| Python Version | Status | Exit Code |\n|---|---|---|\n| `Python 3.9.24+ (heads/3.9:111bbc15b26, Oct 28 2025, 16:51:20) ` | ASAN | 1 |\n| `Python 3.10.19+ (heads/3.10:014261980b1, Oct 28 2025, 16:52:08) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.11.14+ (heads/3.11:88f3f5b5f11, Oct 28 2025, 16:53:08) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.12.12+ (heads/3.12:8cb2092bd8c, Oct 28 2025, 16:54:14) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.13.9+ (heads/3.13:9c8eade20c6, Oct 28 2025, 16:55:18) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.14.0+ (heads/3.14:2e216728038, Oct 28 2025, 16:56:16) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.15.0a1+ (heads/main:f5394c257ce, Oct 28 2025, 16:57:16) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n\u003c/details>\n\n\n**Vulnerable Code**\n\n\u003cdetails>\n\n```c\n/* Buggy Re-entrant Path */\nstatic PyObject *\nTkapp_Call(PyObject *selfptr, PyObject *args)\n{\n Tcl_Obj *objStore[ARGSZ];\n Tcl_Obj **objv = NULL;\n Tcl_Size objc;\n\n /* ... */\n\n objv = Tkapp_CallArgs(args, objStore, &objc);\n if (!objv) {\n return NULL;\n }\n\n /* ... */\n}\n\nstatic Tcl_Obj**\nTkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc)\n{\n Tcl_Obj **objv = objStore;\n Py_ssize_t objc = 0, i;\n\n /* ... */\n\n for (i = 0; i \u003c objc; i++) {\n PyObject *v = PySequence_Fast_GET_ITEM(args, i);\n objv[i] = AsObj(v);\n /* ... */\n }\n /* ... */\n}\n\nstatic Tcl_Obj*\nAsObj(PyObject *value)\n{\n Tcl_Obj *result;\n\n /* ... */\n\n if (PyTuple_Check(value) || PyList_Check(value)) {\n Tcl_Obj **argv;\n Py_ssize_t size, i;\n\n size = PySequence_Fast_GET_SIZE(value);\n /* crashing pointer derived: ((PyListObject *)value)->ob_item */\n\n argv = (Tcl_Obj **) PyMem_Malloc(((size_t)size) * sizeof(Tcl_Obj *));\n if (!argv) {\n PyErr_NoMemory();\n return NULL;\n }\n for (i = 0; i \u003c size; i++) {\n argv[i] = AsObj(PySequence_Fast_GET_ITEM(value, i)); /* Crash site */\n }\n result = Tcl_NewListObj((int)size, argv);\n PyMem_Free(argv);\n return result;\n }\n\n /* ... */\n\n {\n PyObject *v = PyObject_Str(value); /* Reentrant call site */\n if (!v)\n return 0;\n result = AsObj(v);\n Py_DECREF(v);\n return result;\n }\n}\n\n/* Clobbering Path */\nstatic void\nlist_clear_impl(PyListObject *a, bool is_resize)\n{\n PyObject **items = a->ob_item;\n if (items == NULL) {\n return;\n }\n\n /* ... */\n\n Py_ssize_t i = Py_SIZE(a);\n Py_SET_SIZE(a, 0);\n FT_ATOMIC_STORE_PTR_RELEASE(a->ob_item, NULL); /* state mutate site */\n a->allocated = 0;\n while (--i >= 0) {\n Py_XDECREF(items[i]);\n }\n /* ... */\n}\n\nstatic PyObject *\npy_list_clear_impl(PyListObject *self)\n{\n list_clear(self);\n Py_RETURN_NONE;\n}\n```\n\u003c/details>\n\n\n**Sanitizer Output**\n\n\u003cdetails>\n\n```\n=================================================================\n==1649088==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7bdb62a40dc6 bp 0x7fffc6b37870 sp 0x7fffc6b377a0 T0)\n==1649088==The signal is caused by a READ memory access.\n==1649088==Hint: address points to the zero page.\n #0 0x7bdb62a40dc6 in AsObj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Modules/_tkinter.c:1011:27\n #1 0x7bdb62a3f9a8 in Tkapp_CallArgs /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Modules/_tkinter.c:1325:23\n #2 0x7bdb62a3237d in Tkapp_Call /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Modules/_tkinter.c:1509:16\n #3 0x5bcab7d8cfdb in cfunction_call /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/methodobject.c:575:18\n #4 0x5bcab7bc4b81 in _PyObject_MakeTpCall /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/call.c:242:18\n #5 0x5bcab81c4c62 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:1620:35\n #6 0x5bcab8193bf4 in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n #7 0x5bcab8193bf4 in PyEval_EvalCode /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:888:21\n #8 0x5bcab84584d4 in run_mod /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1459:19\n #9 0x5bcab845202d in pyrun_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1293:15\n #10 0x5bcab844f2d3 in _PyRun_SimpleFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:521:13\n #11 0x5bcab844e89e in _PyRun_AnyFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:81:15\n #12 0x5bcab8513b13 in pymain_run_file_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:410:15\n #13 0x5bcab8513b13 in pymain_run_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:429:15\n #14 0x5bcab8510bcb in pymain_run_python /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:691:21\n #15 0x5bcab8510bcb in Py_RunMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:772:5\n #16 0x5bcab85127fb in pymain_main /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:802:12\n #17 0x5bcab8512aa2 in Py_BytesMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:826:12\n #18 0x7bdb6622a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n #19 0x7bdb6622a28a in __libc_start_main csu/../csu/libc-start.c:360:3\n #20 0x5bcab78cf114 in _start (/home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/python+0x6b0114) (BuildId: 0aee20a59f1c25de22733bd0e5f8259ab04406c4)\n\nAddressSanitizer can not provide additional info.\nSUMMARY: AddressSanitizer: SEGV /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Modules/_tkinter.c:1011:27 in AsObj\n==1649088==ABORTING\n```\n\u003c/details>\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-143321\n* gh-143343\n* gh-143344\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jackfromeast","@type":"Person","name":"jackfromeast"},"datePublished":"2025-12-31T14:47:11Z","url":"https://github.com/python/cpython/issues/143310"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:15133c9e-41e8-7c7f-0688-87968aecd2ff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEC2:8AE25:174637B:1ED2F6B:6B020983 |
| html-safe-nonce | 3cf5f3de32211d792c1062a747b7b966ae4939dae08828894e862c514fcc15e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUMyOjhBRTI1OjE3NDYzN0I6MUVEMkY2Qjo2QjAyMDk4MyIsInZpc2l0b3JfaWQiOiIyMjY0NDk2MTU1NDE5MzQ3MzMxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 86f6426d4d9a3c32662ecf4c610c518b66b97b6628782624b669c126cbfffb0e |
| hovercard-subject-tag | issue:3772955863 |
| 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/143310/issue_layout |
| twitter:image | https://opengraph.githubassets.com/37bd661101cdbcfb4c93a362c8d3a3ea9975dd44f1f250b02a690e5b97696cfc/python/cpython/issues/143310 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/37bd661101cdbcfb4c93a362c8d3a3ea9975dd44f1f250b02a690e5b97696cfc/python/cpython/issues/143310 |
| og:image:alt | What happened? Passing a list that contains an object whose __str__ clears the list lets _tkinter’s AsObj recurse through PyObject_Str, which mutates the list while the outer loop still walks it. T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jackfromeast |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width