Fix possible undefined behaviour from signed overflow in struct module.

Backport of revisions 81897, 81898 and 81902 from py3k.
This commit is contained in:
Mark Dickinson 2010-06-11 20:27:05 +00:00
parent b65bd2e3eb
commit 40228912c8
2 changed files with 35 additions and 22 deletions

View file

@ -526,6 +526,12 @@ class StructTest(unittest.TestCase):
def test_crasher(self):
self.assertRaises(MemoryError, struct.pack, "357913941c", "a")
def test_count_overflow(self):
hugecount = '{}b'.format(sys.maxsize+1)
self.assertRaises(struct.error, struct.calcsize, hugecount)
hugecount2 = '{}b{}H'.format(sys.maxsize//2, sys.maxsize//2)
self.assertRaises(struct.error, struct.calcsize, hugecount2)
def test_main():
run_unittest(StructTest)