summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-11-02 18:40:09 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2014-11-02 18:40:09 +0100
commitcc23154d020723dc85d055324861f6a8f54fe0f7 (patch)
tree4443bd4e56e69d5040a3d1df710cebb03447e0b0 /Lib/test/test_bytes.py
parent64f10d4f5e01ab119baa4d0a10403cec444810ce (diff)
downloadcpython-git-cc23154d020723dc85d055324861f6a8f54fe0f7.tar.gz
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 1a351a5372..0177749e21 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])