summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-06-11 07:41:16 +0000
committerGregory P. Smith <greg@mad-scientist.com>2008-06-11 07:41:16 +0000
commit9d53457e599623fbad90833c3448835b42d7e7f9 (patch)
tree41d37b556618eb8e831463c576d854063a33d77b /Lib/test
parent73baefd7fc86a7f8336e4142efcec74c201acf8f (diff)
downloadcpython-git-9d53457e599623fbad90833c3448835b42d7e7f9.tar.gz
Merge in release25-maint r60793:
Added checks for integer overflows, contributed by Google. Some are only available if asserts are left in the code, in cases where they can't be triggered from Python code.
Diffstat (limited to 'Lib/test')
-rwxr-xr-xLib/test/test_array.py17
-rw-r--r--Lib/test/test_struct.py8
2 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index b11c9d601c..34a8f79ce8 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -1009,6 +1009,23 @@ tests.append(FloatTest)
class DoubleTest(FPTest):
typecode = 'd'
minitemsize = 8
+
+ def test_alloc_overflow(self):
+ a = array.array('d', [-1]*65536)
+ try:
+ a *= 65536
+ except MemoryError:
+ pass
+ else:
+ self.fail("a *= 2**16 didn't raise MemoryError")
+ b = array.array('d', [ 2.71828183, 3.14159265, -1])
+ try:
+ b * 1431655766
+ except MemoryError:
+ pass
+ else:
+ self.fail("a * 1431655766 didn't raise MemoryError")
+
tests.append(DoubleTest)
def test_main(verbose=None):
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index e3a4e21784..7ee47bf6e0 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -8,6 +8,7 @@ from test.test_support import TestFailed, verbose, run_unittest, catch_warning
import sys
ISBIGENDIAN = sys.byteorder == "big"
+IS32BIT = sys.maxint == 0x7fffffff
del sys
try:
@@ -568,6 +569,13 @@ class StructTest(unittest.TestCase):
for c in '\x01\x7f\xff\x0f\xf0':
self.assertTrue(struct.unpack('>?', c)[0])
+ def test_crasher(self):
+ if IS32BIT:
+ self.assertRaises(MemoryError, struct.pack, "357913941c", "a")
+ else:
+ print "%s test_crasher skipped on 64bit build."
+
+
def test_main():
run_unittest(StructTest)