]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix possible overflow bugs in unicodedata (closes #23367)
authorBenjamin Peterson <benjamin@python.org>
Mon, 2 Mar 2015 16:17:05 +0000 (11:17 -0500)
committerBenjamin Peterson <benjamin@python.org>
Mon, 2 Mar 2015 16:17:05 +0000 (11:17 -0500)
Misc/NEWS
Modules/unicodedata.c

index be6896151a516b80ddd04891df55a21a10f37f31..288a48433b58c384363151db5739151f099e68ad 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,8 @@ Library
   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.
index 6f9c7e8e83132173c968a038dea5aa16bd912753..6b01fc7616b1f0c26ee4eb153205f4a7719dff27 100644 (file)
@@ -506,8 +506,15 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
 
     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;