Blame SOURCES/00212-pep466-pyunicode_fromformat-raise-overflow.patch

f63228
f63228
# HG changeset patch
f63228
# User Serhiy Storchaka <storchaka@gmail.com>
f63228
# Date 1372008129 -10800
f63228
# Node ID 2f1e8b7fa534b147280fdc9b92e44a7c7305338a
f63228
# Parent  8f0adcb66633ee97e4f7bdeee2104268113b86c3
f63228
Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
f63228
OverflowError when an argument of %c format is out of range.
f63228
f63228
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
f63228
--- a/Objects/unicodeobject.c
f63228
+++ b/Objects/unicodeobject.c
f63228
@@ -740,8 +740,25 @@ PyUnicode_FromFormatV(const char *format
f63228
 
f63228
             switch (*f) {
f63228
             case 'c':
f63228
-                (void)va_arg(count, int);
f63228
+            {
f63228
+                int ordinal = va_arg(count, int);
f63228
+#ifdef Py_UNICODE_WIDE
f63228
+                if (ordinal < 0 || ordinal > 0x10ffff) {
f63228
+                    PyErr_SetString(PyExc_OverflowError,
f63228
+                                    "%c arg not in range(0x110000) "
f63228
+                                    "(wide Python build)");
f63228
+                    goto fail;
f63228
+                }
f63228
+#else
f63228
+                if (ordinal < 0 || ordinal > 0xffff) {
f63228
+                    PyErr_SetString(PyExc_OverflowError,
f63228
+                                    "%c arg not in range(0x10000) "
f63228
+                                    "(narrow Python build)");
f63228
+                    goto fail;
f63228
+                }
f63228
+#endif
f63228
                 /* fall through... */
f63228
+            }
f63228
             case '%':
f63228
                 n++;
f63228
                 break;
f63228