[Python-checkins] cpython (2.7): fix possible overflow bugs in unicodedata (closes #23367)

benjamin.peterson python-checkins at python.org
Mon Mar 2 17:21:42 CET 2015


https://hg.python.org/cpython/rev/3019effc44f2
changeset:   94830:3019effc44f2
branch:      2.7
parent:      94822:f57af1b337ca
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon Mar 02 11:17:05 2015 -0500
summary:
  fix possible overflow bugs in unicodedata (closes #23367)

files:
  Misc/NEWS             |  2 ++
  Modules/unicodedata.c |  9 ++++++++-
  2 files changed, 10 insertions(+), 1 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,8 @@
   posixpath.expandvars().  Fixed all os.path implementations on
   unicode-disabled builds.
 
+- Issue #23367: Fix possible overflows in the unicodedata module.
+
 - Issue #23363: Fix possible overflow in itertools.permutations.
 
 - Issue #23364: Fix possible overflow in itertools.product.
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -506,8 +506,15 @@
 
     stackptr = 0;
     isize = PyUnicode_GET_SIZE(input);
+    space = isize;
     /* Overallocate at most 10 characters. */
-    space = (isize > 10 ? 10 : isize) + isize;
+    if (space > 10) {
+        if (space <= PY_SSIZE_T_MAX - 10)
+            space += 10;
+    }
+    else {
+        space *= 2;
+    }
     result = PyUnicode_FromUnicode(NULL, space);
     if (!result)
         return NULL;

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


More information about the Python-checkins mailing list