gh-151815: Fix crash in t-string iterator on partial construction under OOM - #154714
Closed
Vamsi-klu wants to merge 1 commit into
Closed
gh-151815: Fix crash in t-string iterator on partial construction under OOM#154714Vamsi-klu wants to merge 1 commit into
Vamsi-klu wants to merge 1 commit into
Conversation
…on under OOM Initialize templateiter fields to NULL immediately after PyObject_GC_New so tp_clear/dealloc on the error path does not clear garbage pointers (OOM-0024 / pythongh-151763).
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Vamsi-klu
marked this pull request as draft
July 26, 2026 08:01
Author
|
Closing this PR. Thank you for the review attention. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix OOM-0024 (gh-151815 / umbrella gh-151763): crash when constructing a t-string / template iterator fails partway under memory pressure because
templateiterobjectfields were left uninitialized before a falliblePyObject_GetIter.What the issue is
template_iterdoes:PyObject_GC_Newdoes not zero the struct. On the error path,templateiter_clearrunsPy_CLEARon garbagestringsiter/interpolationsiterpointers → crash / heap corruption under fusil-style allocation failure (OOM-0024).Why I solved it that way
PyObject_GC_Del, becausetemplateiter_clearalready usesPy_CLEAR(NULL-safe). Keeping dealloc unified avoids a second free path.from_strings = 1early so the object is fully consistent if anything inspects it during cleanup.How I did it
Objects/templateobject.cintemplate_iter, after successfulPyObject_GC_New:Then the existing
GetIterassignments overwrite those fields on success.NEWS:
Misc/NEWS.d/next/Core_and_Builtins/…gh-issue-151815….rstImpact
string.templatelib.Template/ t-strings.Testing plan
./python -m test test_string.test_templatelib— PASS.Templatewith interpolations — OK._testcapi.set_nomemorysweep aroundtemplate_iter(not added; happy to add if reviewers want a locked-in repro).Everything else
Requested reviewers (subject-matter experts)
Could the following SMEs take a look when convenient (I cannot formally request reviews from this fork account):
Thank you!