Fix out of bounds read in long_new() for empty bytes with an explicit base. int(b...
authorChristian Heimes <christian@cheimes.de>
Wed, 12 Sep 2012 13:31:43 +0000 (15:31 +0200)
committerChristian Heimes <christian@cheimes.de>
Wed, 12 Sep 2012 13:31:43 +0000 (15:31 +0200)
Objects/longobject.c

index a735e33e0463bf2aa601bd71d29ae6b5212b9dad..f2f63afbf69989bfb57dc17b1da5d1459720da6f 100644 (file)
@@ -4149,8 +4149,8 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
             string = PyByteArray_AS_STRING(x);
         else
             string = PyBytes_AS_STRING(x);
-        if (strlen(string) != (size_t)size) {
-            /* We only see this if there's a null byte in x,
+        if (strlen(string) != (size_t)size || !size) {
+            /* We only see this if there's a null byte in x or x is empty,
                x is a bytes or buffer, *and* a base is given. */
             PyErr_Format(PyExc_ValueError,
                          "invalid literal for int() with base %d: %R",