]> granicus.if.org Git - python/commitdiff
Issue #22335: Fix crash when trying to enlarge a bytearray to 0x7fffffff bytes on...
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 2 Nov 2014 17:41:56 +0000 (18:41 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 2 Nov 2014 17:41:56 +0000 (18:41 +0100)
1  2 
Lib/test/test_bytes.py
Misc/NEWS
Objects/bytearrayobject.c
Objects/obmalloc.c

Simple merge
diff --cc Misc/NEWS
Simple merge
Simple merge
index 2036e379157aac637297b2d6908c9fa60a787d77,3c33255170279b409d7ae2cb30fbdfcd2f90df41..e900cc3bb8173ee97778ff9ae1d3e53b4faf79f8
@@@ -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;