Merged revisions 81904 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81904 | mark.dickinson | 2010-06-11 21:27:05 +0100 (Fri, 11 Jun 2010) | 4 lines
Fix possible undefined behaviour from signed overflow in struct module.
Backport of revisions 81897, 81898 and 81902 from py3k.
........
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index ad754df..c010492 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -12,7 +12,6 @@
import sys
ISBIGENDIAN = sys.byteorder == "big"
IS32BIT = sys.maxsize == 0x7fffffff
-del sys
try:
import _struct
@@ -605,7 +604,12 @@
def test_crasher(self):
self.assertRaises(MemoryError, struct.pack, "357913941c", "a")
+ def test_count_overflow(self):
+ hugecount = '{0}b'.format(sys.maxsize+1)
+ self.assertRaises(struct.error, struct.calcsize, hugecount)
+ hugecount2 = '{0}b{1}H'.format(sys.maxsize//2, sys.maxsize//2)
+ self.assertRaises(struct.error, struct.calcsize, hugecount2)
def test_main():
run_unittest(StructTest)