René's URL Explorer Experiment


Title: run_with_limited_c_stack(size=...) is unsafe below Py_C_STACK_SIZE on platforms without stack-size detection · Issue #159879 · python/cpython · GitHub

Open Graph Title: run_with_limited_c_stack(size=...) is unsafe below Py_C_STACK_SIZE on platforms without stack-size detection · Issue #159879 · python/cpython

X Title: run_with_limited_c_stack(size=...) is unsafe below Py_C_STACK_SIZE on platforms without stack-size detection · Issue #159879 · python/cpython

Description: Bug report Bug description: test.support.run_with_limited_c_stack() runs a test body in a thread with a chosen C stack size. Its default is deliberately conservative, and the comment says why (Lib/test/support/__init__.py:2942-2945): # S...

Open Graph Description: Bug report Bug description: test.support.run_with_limited_c_stack() runs a test body in a thread with a chosen C stack size. Its default is deliberately conservative, and the comment says why (Lib/...

X Description: Bug report Bug description: test.support.run_with_limited_c_stack() runs a test body in a thread with a chosen C stack size. Its default is deliberately conservative, and the comment says why (Lib/...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"run_with_limited_c_stack(size=...) is unsafe below Py_C_STACK_SIZE on platforms without stack-size detection","articleBody":"# Bug report\n\n### Bug description:\n\n`test.support.run_with_limited_c_stack()` runs a test body in a thread with a chosen C stack size. Its\ndefault is deliberately conservative, and the comment says why\n(`Lib/test/support/__init__.py:2942-2945`):\n\n```python\n# Small enough to be exhausted by tens of thousands of recursive calls,\n# but not smaller than Py_C_STACK_SIZE (4 MiB) which the interpreter\n# assumes if it cannot query the thread stack size.\nC_STACK_SIZE = 8 * 1024 * 1024\n```\n\nThat reasoning is sound, but nothing enforces it on callers that pass `size` explicitly, and one of them\ngoes below the limit the comment warns about:\n\n```\nLib/test/test_lazy_import/__init__.py:311\n    @support.run_with_limited_c_stack(depth=10_000, size=256 * 1024)\n\nLib/test/test_profiling/test_sampling_profiler/test_collectors.py:614\n    @run_with_limited_c_stack(size=1024 * 1024)\n```\n\nEvery other caller uses the default.\n\nOn a platform where `hardware_stack_limits()` cannot query the real stack, the interpreter assumes\n`Py_C_STACK_SIZE` and its recursion guard is calibrated to that assumption. Giving the thread *less* than\nthat means the guard's soft limit sits below the real stack base and can never fire, so the test does not\nget a `RecursionError` — it gets SIGSEGV.\n\nThat is what happens on Alpine Linux / musl today: `test_lazy_import.LazyImportTypeTests`\n`.test_deeply_dotted_name` crashes the interpreter. Details and the underlying detection problem are in\n[gh-159876](https://github.com/python/cpython/issues/159876); this report is about the test-side contract, which is worth tightening independently of whether\ndetection is ever fixed for musl.\n\nThe set of affected platforms is exactly the exclusion list in `Python/ceval.c` (main:150-152):\n\n```c\n#  if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && \\\n        !defined(__NetBSD__) && \\\n        (defined(__GLIBC__) || defined(__ANDROID__) || !defined(__linux__))\n```\n\nso **AIX, NetBSD and non-glibc Linux** all run on the assumed-size fallback and are all exposed to a caller\nthat passes a small `size`.\n\nTwo further wrinkles:\n\n- The comment's \"(4 MiB)\" is only the `#else` default. When configure sets `-Wl,-z,stack-size=`, the value\n  becomes `_Py_LINKER_THREAD_STACK_SIZE` instead — 1 MiB on a stock Linux build. There are also\n  `#elif` arms of 320000 (s390x), 1200000 (Android), 1600000 (sparc) and 2000000 (hppa, powerpc64). So the\n  real floor is build- and platform-dependent, and a literal `size=` in a test cannot know it.\n- `size=1024 * 1024` in `test_collectors.py` happens to be exactly `Py_C_STACK_SIZE` on a stock Linux build\n  — not currently failing, but with no margin at all.\n\nThe helper already has everything it needs to notice: it calls `_has_huge_c_stack()`, which reads\n`_testinternalcapi.get_c_recursion_remaining()`. A thread whose reported headroom does not change when its\nstack size changes is one where detection is not working, which is observable from Python.\n\nReproducer for the general shape, independent of `test_lazy_import` (prints the same number twice where\ndetection is unavailable, two different numbers where it works):\n\n```python\nimport threading, _testinternalcapi as T\nfor size in (256 * 1024, 8 * 1024 * 1024):\n    threading.stack_size(size)\n    def show(size=size):\n        print(\"thread stack %7d B -> c_recursion_remaining=%d\"\n              % (size, T.get_c_recursion_remaining()))\n    t = threading.Thread(target=show); t.start(); t.join()\n```\n\n```\nAlpine 3.24 / musl:  262144 -> 1450    8388608 -> 1450\nDebian / glibc:      262144 ->  250    8388608 -> 12650\n```\n\n### CPython versions tested on:\n\n3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159883\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-10-20T12:31:47Z","url":"https://github.com/python/cpython/issues/159879"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f63df60e-91a3-879e-437a-0a9a0bd1a87d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC88A:1201C:3AE928B:4E21F09:6B021B73
html-safe-nonce5a449ce253085a819d3d77d0f8691736bc87b0c94f265aeeb4abc013e4d942b5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODhBOjEyMDFDOjNBRTkyOEI6NEUyMUYwOTo2QjAyMUI3MyIsInZpc2l0b3JfaWQiOiI4MjM2ODA0NzEwNTkwNDU0NjQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacb57df726aae9e8dae3af7039dd4fc1a34aee9944955b5cfced5c5e9d0d4e5f1b
hovercard-subject-tagissue:5941671879
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/159879/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6594f6c9a8ab3775653e14a660604100d3bdb1a300673aff340edc6c0bfc903e/python/cpython/issues/159879
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6594f6c9a8ab3775653e14a660604100d3bdb1a300673aff340edc6c0bfc903e/python/cpython/issues/159879
og:image:altBug report Bug description: test.support.run_with_limited_c_stack() runs a test body in a thread with a chosen C stack size. Its default is deliberately conservative, and the comment says why (Lib/...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameserhiy-storchaka
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/159879#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159879
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159879
Sign uphttps://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/159879
Reloadhttps://github.com/python/cpython/issues/159879
Reloadhttps://github.com/python/cpython/issues/159879
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159879
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159879
run_with_limited_c_stack(size=...) is unsafe below Py_C_STACK_SIZE on platforms without stack-size detectionhttps://github.com/python/cpython/issues/159879#top
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159879#issue-5941671879
gh-159876https://github.com/python/cpython/issues/159876
gh-159879: Do not limit the C stack below what the interpreter assumes #159883https://github.com/python/cpython/pull/159883
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159879#issuecomment-6290965333
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159879#event-33742358303
pythongh-159879: Do not limit the C stack below what the interpreter …https://github.com/serhiy-storchaka/cpython/commit/72165f3d0a6955e2d097271ba93d3ef272238b28
pythongh-159879https://github.com/python/cpython/issues/159879
72165f3https://github.com/serhiy-storchaka/cpython/commit/72165f3d0a6955e2d097271ba93d3ef272238b28
pythongh-159879: Do not limit the C stack below what the interpreter …https://github.com/serhiy-storchaka/cpython/commit/b65f6364496f00fecf43730a53fcffbe557f7bb4
pythongh-159879https://github.com/python/cpython/issues/159879
b65f636https://github.com/serhiy-storchaka/cpython/commit/b65f6364496f00fecf43730a53fcffbe557f7bb4
serhiy-storchakahttps://github.com/serhiy-storchaka
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
on Oct 20, 2026https://github.com/python/cpython/issues/159879#event-33742714611
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/159879
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/159879
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%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.