Title: gh-151763: Fix debug assertion in unicode subtype cleanup under OOM by zainnadeem786 · Pull Request #152164 · python/cpython · GitHub
Open Graph Title: gh-151763: Fix debug assertion in unicode subtype cleanup under OOM by zainnadeem786 · Pull Request #152164 · python/cpython
X Title: gh-151763: Fix debug assertion in unicode subtype cleanup under OOM by zainnadeem786 · Pull Request #152164 · python/cpython
Description: Summary This PR addresses OOM-0030 from gh-151763. It fixes a debug-build assertion that can occur while cleaning up a partially constructed Unicode subtype after an allocation failure. Issue unicode_subtype_new() allocates a non-compact Unicode subtype object and initializes its internal state before allocating the backing character buffer. If allocating that buffer fails, the constructor cleans up using: Py_DECREF(self); At that point the object is valid enough to own a reference, but its internal data pointer is still NULL. During debug builds, deallocation calls unicode_is_singleton(). For length-1 strings that helper reads the first character using: PyUnicode_READ_CHAR(unicode, 0); For a partially initialized non-compact Unicode object this reaches the internal assertion: data != NULL causing the interpreter to abort instead of propagating the pending MemoryError. Fix Before reading the first character, unicode_is_singleton() now detects the temporary construction state: if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode) == NULL) { return 0; } A non-compact Unicode object with a NULL data pointer cannot represent a singleton, so returning 0 is correct while avoiding the invalid debug-only access. The constructor, ownership model, and cleanup logic remain unchanged. Validation Built locally: PCbuild\build.bat -p x64 -c Debug Reproduced the original OOM path using _testcapi.set_nomemory(). Before The reproducer aborted with: Assertion failed: data != NULL Include/cpython/unicodeobject.h After The same allocation-failure sweep completes without triggering the assertion and correctly propagates MemoryError. Tests Executed focused Unicode test suites: PCbuild\amd64\python_d.exe -m test test_str test_capi.test_unicode PCbuild\amd64\python_d.exe -m test test_codecs All passed. I also verified: git diff --check No whitespace issues were reported. Notes No regression test is included. The reproducer relies on _testcapi.set_nomemory() and allocation-failure indices that are build-sensitive, making it difficult to provide a stable CI regression test for this specific OOM path. Addresses OOM-0030 from gh-151763.
Open Graph Description: Summary This PR addresses OOM-0030 from gh-151763. It fixes a debug-build assertion that can occur while cleaning up a partially constructed Unicode subtype after an allocation failure. Issue unico...
X Description: Summary This PR addresses OOM-0030 from gh-151763. It fixes a debug-build assertion that can occur while cleaning up a partially constructed Unicode subtype after an allocation failure. Issue unico...
Opengraph URL: https://github.com/python/cpython/pull/152164
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d548790b-b36d-f634-3fda-eb88828cf3f3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E71C:288515:2D0CA21:3CC7DC7:6A53B911 |
| html-safe-nonce | 23191bb922102e426f6d8e64eef41a2abd1f0fc8387240dc189d71354125532e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzFDOjI4ODUxNToyRDBDQTIxOjNDQzdEQzc6NkE1M0I5MTEiLCJ2aXNpdG9yX2lkIjoiNzU2NDI5NjQ5MzY5MzM4NDk3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 09f76edba7d07d6d3d1e7a6c7424b5cb52a0531bea554f9feb449b0b9b9612c0 |
| hovercard-subject-tag | pull_request:3933425740 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/152164/files |
| twitter:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| og:image:alt | Summary This PR addresses OOM-0030 from gh-151763. It fixes a debug-build assertion that can occur while cleaning up a partially constructed Unicode subtype after an allocation failure. Issue unico... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width