[Python-checkins] cpython (3.3): Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
serhiy.storchaka
python-checkins at python.org
Sun Jun 23 19:55:57 CEST 2013
http://hg.python.org/cpython/rev/f8ede55cf92b
changeset: 84281:f8ede55cf92b
branch: 3.3
parent: 84276:6c23ca1982b3
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jun 23 20:12:14 2013 +0300
summary:
Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
OverflowError when an argument of %c format is out of range.
files:
Lib/test/test_unicode.py | 2 ++
Misc/NEWS | 3 +++
Objects/unicodeobject.c | 9 +++++++--
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -2024,6 +2024,8 @@
# 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)),
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,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
@@ -2489,8 +2489,13 @@
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;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list