OverflowError when an argument of %c format is out of range.
# test "%c"
self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0xabcd)), '\uabcd')
self.assertEqual(PyUnicode_FromFormat(b'%c', c_int(0x10ffff)), '\U0010ffff')
+ with self.assertRaises(OverflowError):
+ PyUnicode_FromFormat(b'%c', c_int(0x110000))
# Issue #18183
self.assertEqual(
PyUnicode_FromFormat(b'%c%c', c_int(0x10000), c_int(0x100000)),
Core and Builtins
-----------------
+- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
+ OverflowError when an argument of %c format is out of range.
+
- Issue #18137: Detect integer overflow on precision in float.__format__()
and complex.__format__().
switch (*f) {
case 'c':
{
- Py_UCS4 ordinal = va_arg(count, int);
- maxchar = Py_MAX(maxchar, ordinal);
+ int ordinal = va_arg(count, int);
+ if (ordinal < 0 || ordinal > MAX_UNICODE) {
+ PyErr_SetString(PyExc_OverflowError,
+ "%c arg not in range(0x110000)");
+ goto fail;
+ }
+ maxchar = Py_MAX(maxchar, (Py_UCS4)ordinal);
n++;
break;
}