Skip to content

Commit 80d0be7

Browse files
[3.15] gh-159739: Check character formatting allocation failure (GH-159746) (#159839)
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 57c563d commit 80d0be7

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
@@ -1256,6 +1256,9 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
12561256
goto done;
12571257
}
12581258
tmp = PyUnicode_FromOrdinal(x);
1259+
if (tmp == NULL) {
1260+
goto done;
1261+
}
12591262
inumeric_chars = 0;
12601263
n_digits = 1;
12611264
maxchar = Py_MAX(maxchar, (Py_UCS4)x);

0 commit comments

Comments
 (0)