Skip to content

Commit fa80b20

Browse files
committed
gh-159739: Check character formatting allocation failure
Propagate the error from PyUnicode_FromOrdinal() before using the result. Backport to 3.15 and 3.14. On 3.14, the equivalent code is in Python/formatter_unicode.c.
1 parent a071788 commit fa80b20

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.

‎Objects/unicode_formatter.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,9 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
12581258
goto done;
12591259
}
12601260
tmp = PyUnicode_FromOrdinal(x);
1261+
if (tmp == NULL) {
1262+
goto done;
1263+
}
12611264
inumeric_chars = 0;
12621265
n_digits = 1;
12631266
maxchar = Py_MAX(maxchar, (Py_UCS4)x);

0 commit comments

Comments
 (0)