diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-06-11 20:27:05 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-06-11 20:27:05 (GMT) |
commit | 40228912c8b3315ff270b50df45f16b5561d529f (patch) | |
tree | 5fff4c4b577b4b9389488bc7b6ca133a75a3b8f5 /Lib/test/test_struct.py | |
parent | b65bd2e3ebac5c81a9d92a00d8bb80ca1ffe5175 (diff) | |
download | cpython-40228912c8b3315ff270b50df45f16b5561d529f.zip cpython-40228912c8b3315ff270b50df45f16b5561d529f.tar.gz cpython-40228912c8b3315ff270b50df45f16b5561d529f.tar.bz2 |
Fix possible undefined behaviour from signed overflow in struct module.
Backport of revisions 81897, 81898 and 81902 from py3k.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index aeb52f8..ce2c22d 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -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) |