https://github.com/python/cpython/commit/bae32d612d30ded7b901760e483f6622b2998bfe
commit: bae32d612d30ded7b901760e483f6622b2998bfe
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-20T08:45:25-07:00
summary:

[3.14] gh-159739: Check character formatting allocation failure (GH-159746) 
(#159840)

Propagate the error from PyUnicode_FromOrdinal() before using the
result.
(cherry picked from commit 5b0ab21364813b4f78e04a1a6b2805f6bdcc5d46)

Co-authored-by: Jelle Zijlstra <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst
M Python/formatter_unicode.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst
new file mode 100644
index 00000000000000..a552d06ff7bb89
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.173d49.rst
@@ -0,0 +1,2 @@
+Avoid a crash if formatting an integer with the ``c`` presentation type runs
+out of memory.
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 30807f428c7d71..562956fb3e1e5e 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -1021,6 +1021,9 @@ format_long_internal(PyObject *value, const 
InternalFormatSpec *format,
             goto done;
         }
         tmp = PyUnicode_FromOrdinal(x);
+        if (tmp == NULL) {
+            goto done;
+        }
         inumeric_chars = 0;
         n_digits = 1;
         maxchar = Py_MAX(maxchar, (Py_UCS4)x);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to