Mercurial > cpython-lru_cache-weakref
diff Objects/bufferobject.c @ 45337:8cbe0bd93c28 2.5
Added checks for integer overflows, contributed by Google. Some are
only available if asserts are left in the code, in cases where they
can't be triggered from Python code.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Thu, 14 Feb 2008 11:26:18 +0000 |
| parents | 10f8a8a919e2 |
| children | 0aafd1ae5120 |
line wrap: on
line diff
--- a/Objects/bufferobject.c Thu Feb 14 04:57:08 2008 +0000 +++ b/Objects/bufferobject.c Thu Feb 14 11:26:18 2008 +0000 @@ -207,7 +207,10 @@ "size must be zero or positive"); return NULL; } - /* XXX: check for overflow in multiply */ + if (sizeof(*b) > PY_SSIZE_T_MAX - size) { + /* unlikely */ + return PyErr_NoMemory(); + } /* Inline PyObject_New */ o = (PyObject *)PyObject_MALLOC(sizeof(*b) + size); if ( o == NULL ) @@ -397,6 +400,8 @@ if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 ) return NULL; + assert(count <= PY_SIZE_MAX - size); + ob = PyString_FromStringAndSize(NULL, size + count); if ( ob == NULL ) return NULL;
