Issue #22335: Fix crash when trying to enlarge a bytearray to 0x7fffffff bytes on a 32-bit platform.

This commit is contained in:
Antoine Pitrou 2014-11-02 18:41:56 +01:00
commit 8a03896cac
4 changed files with 34 additions and 11 deletions

View file

@ -13,9 +13,11 @@ import functools
import pickle
import tempfile
import unittest
import test.support
import test.string_tests
import test.buffer_tests
from test.support import bigaddrspacetest, MAX_Py_ssize_t
if sys.flags.bytes_warning:
@ -111,6 +113,17 @@ class BaseBytesTest:
self.assertRaises(ValueError, self.type2test, [sys.maxsize+1])
self.assertRaises(ValueError, self.type2test, [10**100])
@bigaddrspacetest
def test_constructor_overflow(self):
size = MAX_Py_ssize_t
self.assertRaises((OverflowError, MemoryError), self.type2test, size)
try:
# Should either pass or raise an error (e.g. on debug builds with
# additional malloc() overhead), but shouldn't crash.
bytearray(size - 4)
except (OverflowError, MemoryError):
pass
def test_compare(self):
b1 = self.type2test([1, 2, 3])
b2 = self.type2test([1, 2, 3])