René's URL Explorer Experiment


Title: import_run_extension() can return on the wrong interpreter after _PyUnicode_Copy() failure · Issue #150454 · python/cpython · GitHub

Open Graph Title: import_run_extension() can return on the wrong interpreter after _PyUnicode_Copy() failure · Issue #150454 · python/cpython

X Title: import_run_extension() can return on the wrong interpreter after _PyUnicode_Copy() failure · Issue #150454 · python/cpython

Description: Bug report Bug description: Summary import_run_extension() can return NULL while the current thread is still switched to the main interpreter. This happens in the subinterpreter extension import path when copying info->filename with _PyU...

Open Graph Description: Bug report Bug description: Summary import_run_extension() can return NULL while the current thread is still switched to the main interpreter. This happens in the subinterpreter extension import pa...

X Description: Bug report Bug description: Summary import_run_extension() can return NULL while the current thread is still switched to the main interpreter. This happens in the subinterpreter extension import pa...

Opengraph URL: https://github.com/python/cpython/issues/150454

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"import_run_extension() can return on the wrong interpreter after _PyUnicode_Copy() failure","articleBody":"# Bug report\n\n### Bug description:\n\n## Summary\n\n`import_run_extension()` can return `NULL` while the current thread is still switched to the main interpreter. This happens in the subinterpreter extension import path when copying `info-\u003efilename` with `_PyUnicode_Copy()` fails.\n\nThe function switches from the importing subinterpreter to the main interpreter before calling the extension module init function. For single-phase init modules, it then copies the original filename because the original object may have been allocated by the subinterpreter's obmalloc:\n\n```c\nfilename = _PyUnicode_Copy(info-\u003efilename);\nif (filename == NULL) {\n    return NULL;\n}\n```\n\nThat direct `return NULL` bypasses the `main_finally` cleanup path, including `switch_back_from_main_interpreter()`. The caller resumes with the wrong interpreter current for the thread, which can lead to a crash or interpreter state corruption.\n\nThis is a sub-issue of https://github.com/python/cpython/issues/146102 with [gist details](https://gist.github.com/devdanzin/432d9af1a8833bef53bc9ae342310622)\n\n## Affected area\n\n`Python/import.c`, in `import_run_extension()`, around the single-phase extension import handling after switching to the main interpreter.\n\n\n## Reproducer\n\nThe following script runs each attempt in a child process so that a vulnerable build can crash without taking down the driver process. It requires a CPython build tree with `_interpreters`, `_testcapi`, and `_testsinglephase` available.\n\n```python\nfrom __future__ import annotations\n\nimport argparse\nimport subprocess\nimport sys\nimport textwrap\n\n\nCHILD = r\"\"\"\nimport _interpreters\nimport _testsinglephase\n\nfilename = _testsinglephase.__file__\nscript = f'''\nimport _testcapi\nfrom test.test_import import import_extension_from_file\n\n_testcapi.set_nomemory(START, STOP)\ntry:\n    import_extension_from_file('_testsinglephase_basic_copy', {filename!r})\nfinally:\n    _testcapi.remove_mem_hooks()\n'''\n\ninterp = _interpreters.create()\ntry:\n    exc = _interpreters.run_string(interp, script)\nfinally:\n    _interpreters.destroy(interp)\n\nif exc is None:\n    print(\"import unexpectedly succeeded\")\nelse:\n    print(f\"{exc.type.__name__}: {exc.msg}\")\n\"\"\"\n\n\ndef run_one(python: str, start: int) -\u003e subprocess.CompletedProcess[bytes]:\n    code = CHILD.replace(\"START\", str(start)).replace(\"STOP\", str(start + 1))\n    return subprocess.run(\n        [python, \"-X\", \"faulthandler\", \"-c\", code],\n        stdout=subprocess.PIPE,\n        stderr=subprocess.PIPE,\n    )\n\n\ndef main() -\u003e int:\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--python\", default=sys.executable)\n    parser.add_argument(\"--start\", type=int, default=1)\n    parser.add_argument(\"--stop\", type=int, default=50)\n    args = parser.parse_args()\n\n    for start in range(args.start, args.stop + 1):\n        proc = run_one(args.python, start)\n        out = proc.stdout.decode(\"utf-8\", \"replace\").strip()\n        err = proc.stderr.decode(\"utf-8\", \"replace\").strip()\n        if proc.returncode:\n            print(f\"CRASH start={start} returncode={proc.returncode}\")\n            if out:\n                print(\"stdout:\")\n                print(textwrap.indent(out, \"    \"))\n            if err:\n                print(\"stderr:\")\n                print(textwrap.indent(err, \"    \"))\n            return 1\n        print(f\"ok start={start}: {out}\")\n\n    print(\"No child process crashed in the scanned range.\")\n    return 0\n\n\nif __name__ == \"__main__\":\n    raise SystemExit(main())\n```\n\nExample command on Windows:\n\n```powershell\n.\\PCbuild\\amd64\\python.exe repro_import_run_extension_copy_failure.py --start 1 --stop 50\n```\n\nOn a vulnerable build, one of the child processes can terminate with an access violation or another abnormal return code.\n\nOn a fixed build, allocation failures in this area should be converted into a controlled subinterpreter-side `ImportError`, for example:\n\n```text\nImportError: failed to import from subinterpreter due to exception\n```\n\n## Expected behavior\n\nAny error after switching to the main interpreter must go through the cleanup path that switches back to the original interpreter before returning to the caller.\n\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150455\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/lpyu001","@type":"Person","name":"lpyu001"},"datePublished":"2026-05-26T07:15:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/150454/cpython/issues/150454"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:586b69d7-f397-4e45-10d8-b801f9093ac2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9F8A:2380C5:AF5ACE0:B2B75D0:6A50B97F
html-safe-nonced3b6a362d0be868440d71e15f981a09b9eacd07675f29fffb14f841162251520
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjhBOjIzODBDNTpBRjVBQ0UwOkIyQjc1RDA6NkE1MEI5N0YiLCJ2aXNpdG9yX2lkIjoiMjY1MTg2NzM0NzU1MjM1MjYzOSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9
visitor-hmacccf909b37e3c612b2ddcc457762d90f536b78fed4b7aede7a69378de112131ec
hovercard-subject-tagissue:4522214937
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/150454/issue_layout
twitter:imagehttps://opengraph.githubassets.com/63c929b2c1a259f6ff53248fc76ab15dc0c011168686bfc5a9eb845b474fb64a/python/cpython/issues/150454
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/63c929b2c1a259f6ff53248fc76ab15dc0c011168686bfc5a9eb845b474fb64a/python/cpython/issues/150454
og:image:altBug report Bug description: Summary import_run_extension() can return NULL while the current thread is still switched to the main interpreter. This happens in the subinterpreter extension import pa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelpyu001
hostnamegithub.com
expected-hostnamegithub.com
None63772747707af4093f0d5fc7aa1bb3bb55f412a9865207c4f421aa34c64cc404
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseded53fe94e3ff1bb4dbf8cc77e285396c92580fb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/150454#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150454
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150454
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/150454
Reloadhttps://github.com/python/cpython/issues/150454
Reloadhttps://github.com/python/cpython/issues/150454
Please reload this pagehttps://github.com/python/cpython/issues/150454
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/150454
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.7k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
import_run_extension() can return on the wrong interpreter after _PyUnicode_Copy() failurehttps://github.com/python/cpython/issues/150454#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/lpyu001
lpyu001https://github.com/lpyu001
on May 26, 2026https://github.com/python/cpython/issues/150454#issue-4522214937
#146102https://github.com/python/cpython/issues/146102
gist detailshttps://gist.github.com/devdanzin/432d9af1a8833bef53bc9ae342310622
gh-150454: Fix wrong-interpreter return in import_run_extension error path #150455https://github.com/python/cpython/pull/150455
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.