diff Modules/_codecsmodule.c @ 79529:152d85b2da3a 3.3

Issue #16096: Fix several occurrences of potential signed integer overflow. Thanks Serhiy Storchaka.
author Mark Dickinson <mdickinson@enthought.com>
date Sat, 06 Oct 2012 18:04:49 +0100
parents fe2be7d35660
children e7f6cef7a4cc
line wrap: on
line diff
--- a/Modules/_codecsmodule.c	Sat Oct 06 18:45:47 2012 +0300
+++ b/Modules/_codecsmodule.c	Sat Oct 06 18:04:49 2012 +0100
@@ -177,12 +177,12 @@
         return NULL;
 
     size = PyBytes_GET_SIZE(str);
-    newsize = 4*size;
-    if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
+    if (size > PY_SSIZE_T_MAX / 4) {
         PyErr_SetString(PyExc_OverflowError,
             "string is too large to encode");
             return NULL;
     }
+    newsize = 4*size;
     v = PyBytes_FromStringAndSize(NULL, newsize);
 
     if (v == NULL) {