From 2d6f1ffb202690ff45f25d9477ce2412b75b6d43 Mon Sep 17 00:00:00 2001 From: Vamsi-klu Date: Sun, 26 Jul 2026 07:10:53 +0000 Subject: [PATCH] gh-151673: Fix crash in warnings setup_context when filename alloc fails Check PyUnicode_FromString(\"\") for NULL before continuing (OOM-0001 / gh-151763). --- .../2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst | 1 + Python/_warnings.c | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst new file mode 100644 index 000000000000000..1126f04790647d6 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst @@ -0,0 +1 @@ +Fix a crash in the warnings module when allocating a synthetic filename fails under memory pressure. diff --git a/Python/_warnings.c b/Python/_warnings.c index 4f6de50efa14a8e..af546acd2db3a58 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1035,6 +1035,9 @@ setup_context(Py_ssize_t stack_level, globals = interp->sysdict; *filename = PyUnicode_FromString(""); *lineno = 0; + if (*filename == NULL) { + return 0; /* nothing else allocated yet on this path */ + } } else { globals = f->f_frame->f_globals;