summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-11-02 17:41:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-11-02 17:41:56 (GMT)
commit8a03896cace7cf2b8634c1409722fe6d3f9c8bcd (patch)
tree23f5e2d94a09abf5a2c80d095c26bd7f5e391dac /Lib/test/test_bytes.py
parentc58e3a449bfcf42b4d3ec0495960472adaaa952e (diff)
parentcc23154d020723dc85d055324861f6a8f54fe0f7 (diff)
downloadcpython-8a03896cace7cf2b8634c1409722fe6d3f9c8bcd.zip
cpython-8a03896cace7cf2b8634c1409722fe6d3f9c8bcd.tar.gz
cpython-8a03896cace7cf2b8634c1409722fe6d3f9c8bcd.tar.bz2
Issue #22335: Fix crash when trying to enlarge a bytearray to 0x7fffffff bytes on a 32-bit platform.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 23a411e..1e11437 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -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])