[Python-checkins] cpython (2.7): Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise

serhiy.storchaka python-checkins at python.org
Sun Jun 23 19:55:59 CEST 2013


http://hg.python.org/cpython/rev/2f1e8b7fa534
changeset:   84283:2f1e8b7fa534
branch:      2.7
parent:      84278:8f0adcb66633
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Jun 23 20:22:09 2013 +0300
summary:
  Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
OverflowError when an argument of %c format is out of range.

files:
  Misc/NEWS               |   3 +++
  Objects/unicodeobject.c |  19 ++++++++++++++++++-
  2 files changed, 21 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
 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__().
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -740,8 +740,25 @@
 
             switch (*f) {
             case 'c':
-                (void)va_arg(count, int);
+            {
+                int ordinal = va_arg(count, int);
+#ifdef Py_UNICODE_WIDE
+                if (ordinal < 0 || ordinal > 0x10ffff) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "%c arg not in range(0x110000) "
+                                    "(wide Python build)");
+                    goto fail;
+                }
+#else
+                if (ordinal < 0 || ordinal > 0xffff) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "%c arg not in range(0x10000) "
+                                    "(narrow Python build)");
+                    goto fail;
+                }
+#endif
                 /* fall through... */
+            }
             case '%':
                 n++;
                 break;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list