Title: Concurrent codecs.unregister() calls can crash in PyCodec_Unregister · Issue #157078 · python/cpython · GitHub
Open Graph Title: Concurrent codecs.unregister() calls can crash in PyCodec_Unregister · Issue #157078 · python/cpython
X Title: Concurrent codecs.unregister() calls can crash in PyCodec_Unregister · Issue #157078 · python/cpython
Description: Description PyCodec_Unregister() reads PyList_GET_SIZE(codec_search_path) for its loop condition before acquiring search_path_mutex, then acquires the mutex and fetches index i with PyList_GetItemRef(). Another unregister call can shorte...
Open Graph Description: Description PyCodec_Unregister() reads PyList_GET_SIZE(codec_search_path) for its loop condition before acquiring search_path_mutex, then acquires the mutex and fetches index i with PyList_GetItemR...
X Description: Description PyCodec_Unregister() reads PyList_GET_SIZE(codec_search_path) for its loop condition before acquiring search_path_mutex, then acquires the mutex and fetches index i with PyList_GetItemR...
Opengraph URL: https://github.com/python/cpython/issues/157078
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Concurrent codecs.unregister() calls can crash in PyCodec_Unregister","articleBody":"**Description**\n\n`PyCodec_Unregister()` reads `PyList_GET_SIZE(codec_search_path)` for its loop condition before acquiring `search_path_mutex`, then acquires the mutex and fetches index `i` with `PyList_GetItemRef()`. Another unregister call can shorten the list between those operations. The indexed fetch then returns `NULL`, but the function later calls `Py_DECREF(item)` unconditionally.\n\n**Observed Behavior**\n\nEight threads repeatedly registering and unregistering one search function caused an ASan SEGV on address `0x0c` in `Py_DECREF()` at `Python/codecs.c:83` after 0.23 seconds. The same executable completed the four-second GIL-enabled control.\n\n**Affected Version**\n\nCPython 3.14.7 at commit `823f0323ee6ec1402088b73bce1a38473cac36dc`, tested with a free-threaded ASan build.\n\n**Reproduction**\n\n```sh\nASAN_OPTIONS=detect_leaks=0:halt_on_error=1 PYTHON_GIL=0 python3.14 poc/reproduce.py 10\n```\n\nSetting `PYTHON_GIL=1` provides the GIL-enabled control.\n\n**PoC Source Code**\n\n`poc/reproduce.py`\n\n```python\nimport codecs\nimport sys\nimport threading\nimport time\n\n\nduration = float(sys.argv[1]) if len(sys.argv) > 1 else 10.0\nstop = threading.Event()\n\n\ndef search(name):\n return None\n\n\ncodecs.register(search)\n\n\ndef exercise():\n while not stop.is_set():\n codecs.unregister(search)\n codecs.register(search)\n\n\nthreads = [threading.Thread(target=exercise) for _ in range(8)]\nfor thread in threads:\n thread.start()\ntime.sleep(duration)\nstop.set()\nfor thread in threads:\n thread.join()\nprint(\"completed\")\n```\n","author":{"url":"https://github.com/Nievesjyl","@type":"Person","name":"Nievesjyl"},"datePublished":"2026-09-07T17:35:10Z","url":"https://github.com/python/cpython/issues/157078"}
| 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:d8b52603-bde4-291c-0c77-6d4309ad5d26 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C42A:2023BA:2D0087:3BFAF2:6B023363 |
| html-safe-nonce | 4029bd053f917e6c203886c475a6a0f9d834f3c96404f014bfa3d384559dd92c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDJBOjIwMjNCQToyRDAwODc6M0JGQUYyOjZCMDIzMzYzIiwidmlzaXRvcl9pZCI6IjgzMjUyODYwNDA1MjQ5NjA2MTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 637515d5287112d8ee0896d348f5f6fb38c15b7d0a5b8df3014c7476d71feac1 |
| hovercard-subject-tag | issue:5377588482 |
| 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/157078/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c2ec97a414e36780b21a84da6f86858a1d3885002f3d55206039db6973949376/python/cpython/issues/157078 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c2ec97a414e36780b21a84da6f86858a1d3885002f3d55206039db6973949376/python/cpython/issues/157078 |
| og:image:alt | Description PyCodec_Unregister() reads PyList_GET_SIZE(codec_search_path) for its loop condition before acquiring search_path_mutex, then acquires the mutex and fetches index i with PyList_GetItemR... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Nievesjyl |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width