René's URL Explorer Experiment


Title: gh-151763: Fix NULL deref in `os._path_normpath()` by zainnadeem786 · Pull Request #151779 · python/cpython · GitHub

Open Graph Title: gh-151763: Fix NULL deref in `os._path_normpath()` by zainnadeem786 · Pull Request #151779 · python/cpython

X Title: gh-151763: Fix NULL deref in `os._path_normpath()` by zainnadeem786 · Pull Request #151779 · python/cpython

Description: Summary This PR addresses OOM-0028 from gh-151763. It fixes a NULL dereference in os__path_normpath_impl() when memory allocation fails while normalizing a bytes path. Issue os__path_normpath_impl() builds a Unicode result using either PyUnicode_FromOrdinal() or PyUnicode_FromWideChar(). For bytes input, the function then converts that Unicode result back to bytes using PyUnicode_EncodeFSDefault(). Before this change, the result of PyUnicode_FromWideChar() was not checked before the bytes-path encoding branch. Under memory pressure, PyUnicode_FromWideChar() can return NULL with a pending MemoryError. The existing code could then pass that NULL value into PyUnicode_EncodeFSDefault(), causing a crash. Fix Add an explicit NULL check immediately after creating result and before the bytes-path encoding branch. if (result == NULL) { return NULL; } This preserves the pending MemoryError and prevents PyUnicode_EncodeFSDefault() from receiving a NULL object. Validation I validated this using a CPython debug build on Windows: PCbuild\build.bat -p x64 -c Debug Then I used _testcapi.set_nomemory() to inject allocation failures while calling: os.path.normpath(b"a\\..\\b\\c") Before the fix With the NULL guard removed, allocation index 2 crashed: IDX 2 RC 3221225477 3221225477 is 0xC0000005, Windows STATUS_ACCESS_VIOLATION. After the fix With the NULL guard restored, the same allocation index returned a clean MemoryError instead of crashing: IDX 2 RC 10 MEMORYERROR This confirms that the failing OOM path now propagates the allocation failure instead of dereferencing NULL. Tests Focused ntpath tests passed: PCbuild\amd64\python_d.exe -m unittest -v ` test.test_ntpath.TestNtpath.test_normpath ` test.test_ntpath.TestNtpath.test_normpath_invalid_paths ` test.test_ntpath.NtCommonTest.test_normpath_issue5827 ` test.test_ntpath.NtCommonTest.test_normpath_issue106242 Result: Ran 4 tests in 0.009s OK I also checked the patch with: git diff --check -- Modules/posixmodule.c No regression test is included in this PR. The OOM reproducer depends on allocation-failure injection and allocation indexes that can be build-sensitive. The fix itself is a minimal local NULL guard. Addresses OOM-0028 from gh-151763.

Open Graph Description: Summary This PR addresses OOM-0028 from gh-151763. It fixes a NULL dereference in os__path_normpath_impl() when memory allocation fails while normalizing a bytes path. Issue os__path_normpath_impl(...

X Description: Summary This PR addresses OOM-0028 from gh-151763. It fixes a NULL dereference in os__path_normpath_impl() when memory allocation fails while normalizing a bytes path. Issue os__path_normpath_impl(...

Opengraph URL: https://github.com/python/cpython/pull/151779

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a4c8bb34-1964-396d-e541-3f6d897f340b
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBC44:1461A1:184A0:1EAB9:6A52DDF1
html-safe-nonce4c76708e273634f217b463dac37829c371864a9807d9fdab60326f06a00d9637
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzQ0OjE0NjFBMToxODRBMDoxRUFCOTo2QTUyRERGMSIsInZpc2l0b3JfaWQiOiIxNjQ5MjQ5NTExOTU5MzU0ODY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd9ee8349b767b508c61f1ca08b0c5acdc32024003142f9010ccf04a4133d7f6b
hovercard-subject-tagpull_request:3903133217
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/151779/files
twitter:imagehttps://avatars.githubusercontent.com/u/165761530?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/165761530?s=400&v=4
og:image:altSummary This PR addresses OOM-0028 from gh-151763. It fixes a NULL dereference in os__path_normpath_impl() when memory allocation fails while normalizing a bytes path. Issue os__path_normpath_impl(...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
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-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/151779/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F151779%2Ffiles
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%2Fpull%2F151779%2Ffiles
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%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/151779/files
Reloadhttps://github.com/python/cpython/pull/151779/files
Reloadhttps://github.com/python/cpython/pull/151779/files
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k 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
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
StanFromIrelandhttps://github.com/StanFromIreland
python:mainhttps://github.com/python/cpython/tree/main
zainnadeem786:fix/oom-investigationhttps://github.com/zainnadeem786/cpython/tree/fix/oom-investigation
Conversation 17 https://github.com/python/cpython/pull/151779
Commits 4 https://github.com/python/cpython/pull/151779/commits
Checks 67 https://github.com/python/cpython/pull/151779/checks
Files changed https://github.com/python/cpython/pull/151779/files
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
gh-151763: Fix NULL deref in os._path_normpath() https://github.com/python/cpython/pull/151779/files#top
Show all changes 4 commits https://github.com/python/cpython/pull/151779/files
6416834 gh-151763: Fix OOM NULL check in ntpath normpath zainnadeem786 Jun 20, 2026 https://github.com/python/cpython/pull/151779/commits/6416834a8acac7971218c5f4a07b352226dd8774
ef4a99a gh-151763: Add NEWS entry for OOM-0028 fix zainnadeem786 Jun 20, 2026 https://github.com/python/cpython/pull/151779/commits/ef4a99abd3a779acc9c04cc08494399d8ce5caf7
73a2b50 gh-151763: Move NEWS entry to Library zainnadeem786 Jun 20, 2026 https://github.com/python/cpython/pull/151779/commits/73a2b50d2c7cef8e5b8125e635487b59ac7ea8e6
c8b5a79 Remove NEWS entry zainnadeem786 Jun 24, 2026 https://github.com/python/cpython/pull/151779/commits/c8b5a796b157527afefa6cc09edc875a4740b909
Clear filters https://github.com/python/cpython/pull/151779/files
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
Modules/posixmodule.chttps://github.com/python/cpython/pull/151779/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
View file https://github.com/zainnadeem786/cpython/blob/c8b5a796b157527afefa6cc09edc875a4740b909/Modules/posixmodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151779/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151779/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/151779/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
Please reload this pagehttps://github.com/python/cpython/pull/151779/files
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.