gh-151673: Fix crash in warnings setup_context when filename alloc fails#154715
gh-151673: Fix crash in warnings setup_context when filename alloc fails#154715Vamsi-klu wants to merge 1 commit into
Conversation
…loc fails Check PyUnicode_FromString(\"<sys>\") for NULL before continuing (OOM-0001 / pythongh-151763).
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
|
Thank you so much for taking the time to review this and for the clear feedback. I really appreciate it. I’m sorry for opening this PR with an agent and for creating a duplicate when there was already an open PR. That was against CPython’s policy, and I take full responsibility. I understand why that matters for the project and for maintainers’ time. I’ve tightened my process so this doesn’t happen again: I won’t open CPython PRs via agents, I’ll always check for existing PRs before filing anything new, and I’ve added stricter guidelines for my agent so it doesn’t invent or submit work like this on my behalf. I won’t repeat this. Thanks again for the patience and for looking out for the project’s standards. I’m grateful you flagged it. |
Summary
Fix OOM-0001 (gh-151673 / umbrella gh-151763): crash in the warnings module when allocating the synthetic
"<sys>"filename fails under memory pressure.What the issue is
In
setup_context(Python/_warnings.c), when no frame is available:If that allocation returns
NULL, setup still proceeds / returns success-ish paths that laterPy_DECREF(*filename)indo_warnorhandle_erroron a NULL/invalid pointer. The sibling"<string>"module path already checks forNULL;"<sys>"did not.Why I solved it that way
PyUnicode_FromString.return 0rather thangoto handle_erroron this path, because at that moment nothing else has been allocated (*registry/*modulenot set yet), andhandle_errorhistorically didPy_DECREF(*filename)which is unsafe when*filenameis NULL."<string>"path alone — it already has the correct check.How I did it
NEWS entry under Core and Builtins for gh-151673.
Impact
Testing plan
./python -m test test_warnings— PASS.warnings.warn("x")— OK.Everything else
Py_DECREF(NULL)insetup_context/do_warn(_warnings.c) when emitting a warning under MemoryError #151673.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!