Skip to content

Commit bae32d6

Browse files
[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 5b0ab21) Co-authored-by: Jelle Zijlstra <jelle@openai.com>
1 parent be41ce5 commit bae32d6

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid a crash if formatting an integer with the ``c`` presentation type runs
2+
out of memory.

‎Python/formatter_unicode.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,9 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
10211021
goto done;
10221022
}
10231023
tmp = PyUnicode_FromOrdinal(x);
1024+
if (tmp == NULL) {
1025+
goto done;
1026+
}
10241027
inumeric_chars = 0;
10251028
n_digits = 1;
10261029
maxchar = Py_MAX(maxchar, (Py_UCS4)x);

0 commit comments

Comments
 (0)