From: Antoine Pitrou Date: Sun, 2 Nov 2014 17:41:56 +0000 (+0100) Subject: Issue #22335: Fix crash when trying to enlarge a bytearray to 0x7fffffff bytes on... X-Git-Tag: v3.5.0a1~534 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a03896cace7cf2b8634c1409722fe6d3f9c8bcd;p=python Issue #22335: Fix crash when trying to enlarge a bytearray to 0x7fffffff bytes on a 32-bit platform. --- 8a03896cace7cf2b8634c1409722fe6d3f9c8bcd diff --cc Objects/obmalloc.c index 2036e37915,3c33255170..e900cc3bb8 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@@ -1828,14 -1754,11 +1828,14 @@@ _PyMem_DebugAlloc(int use_calloc, void bumpserialno(); total = nbytes + 4*SST; - if (total < nbytes) - /* overflow: can't represent total as a size_t */ + if (nbytes > PY_SSIZE_T_MAX - 4*SST) + /* overflow: can't represent total as a Py_ssize_t */ return NULL; - p = (uchar *)api->alloc.malloc(api->alloc.ctx, total); + if (use_calloc) + p = (uchar *)api->alloc.calloc(api->alloc.ctx, 1, total); + else + p = (uchar *)api->alloc.malloc(api->alloc.ctx, total); if (p == NULL) return NULL;