Content-Length: 2954 | pFad | http://github.com/python/cpython/pull/150275.patch
6A1267DF
From a63c8723e7821fc7e7b198ac6f23d87e1f3b365a Mon Sep 17 00:00:00 2001
From: grantlouisherman
Date: Fri, 22 May 2026 17:48:34 -0400
Subject: [PATCH 1/2] type-crash(): throw a no mem error when malloc fails in
tokenizer
Signed-off-by: grantlouisherman
---
Parser/lexer/state.c | 5 ++++-
Parser/tokenizer/helpers.c | 2 ++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Parser/lexer/state.c b/Parser/lexer/state.c
index 3663dc3eb7f9f69..5cf9b4d768c3ebb 100644
--- a/Parser/lexer/state.c
+++ b/Parser/lexer/state.c
@@ -15,8 +15,11 @@ _PyTokenizer_tok_new(void)
struct tok_state *tok = (struct tok_state *)PyMem_Calloc(
1,
sizeof(struct tok_state));
- if (tok == NULL)
+ if (tok == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
+
tok->buf = tok->cur = tok->inp = NULL;
tok->fp_interactive = 0;
tok->interactive_src_start = NULL;
diff --git a/Parser/tokenizer/helpers.c b/Parser/tokenizer/helpers.c
index 9542969ad3127b9..c69e66d0ab9b7a8 100644
--- a/Parser/tokenizer/helpers.c
+++ b/Parser/tokenizer/helpers.c
@@ -193,6 +193,7 @@ _PyTokenizer_new_string(const char *s, Py_ssize_t len, struct tok_state *tok)
char* result = (char *)PyMem_Malloc(len + 1);
if (!result) {
tok->done = E_NOMEM;
+ PyErr_NoMemory();
return NULL;
}
memcpy(result, s, len);
@@ -221,6 +222,7 @@ _PyTokenizer_translate_newlines(const char *s, int exec_input, int preserve_crlf
buf = PyMem_Malloc(needed_length);
if (buf == NULL) {
tok->done = E_NOMEM;
+ PyErr_NoMemory();
return NULL;
}
for (current = buf; *s; s++, current++) {
From f046a3e93797df61bede44c100a2277586664d17 Mon Sep 17 00:00:00 2001
From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com>
Date: Fri, 22 May 2026 21:52:40 +0000
Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?=
=?UTF-8?q?rb=5Fit.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../2026-05-22-21-52-38.gh-issue-150207.l2BUtI.rst | 1 +
1 file changed, 1 insertion(+)
create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-05-22-21-52-38.gh-issue-150207.l2BUtI.rst
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-22-21-52-38.gh-issue-150207.l2BUtI.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-22-21-52-38.gh-issue-150207.l2BUtI.rst
new file mode 100644
index 000000000000000..109a858db6b09bb
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-22-21-52-38.gh-issue-150207.l2BUtI.rst
@@ -0,0 +1 @@
+fails in the tokenizer's ``_PyTokenizer_translate_newlines`` helper, so the out-of-memory condition is propagated as a proper Python exception instead of only being recorded in ``tok->done``.
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/python/cpython/pull/150275.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy