diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 10:55:39 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 10:55:39 (GMT) |
commit | 74f49ab28b91d3c23524356230feb2724ee9b23f (patch) | |
tree | 0ddd5e8899d06c974dfc25a7dfc298e3f6f70039 /Lib/test/string_tests.py | |
parent | ac7b49f4076a4336915d13a4aa19feaeadd29d62 (diff) | |
download | cpython-74f49ab28b91d3c23524356230feb2724ee9b23f.zip cpython-74f49ab28b91d3c23524356230feb2724ee9b23f.tar.gz cpython-74f49ab28b91d3c23524356230feb2724ee9b23f.tar.bz2 |
Issue #15989: Fix several occurrences of integer overflow
when result of PyInt_AsLong() or PyLong_AsLong() narrowed
to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r-- | Lib/test/string_tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index a161512..f73d0ee 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -5,6 +5,7 @@ Common tests shared by test_str, test_unicode, test_userstring and test_string. import unittest, string, sys, struct from test import test_support from UserList import UserList +import _testcapi class Sequence: def __init__(self, seq='wxyz'): self.seq = seq @@ -1113,6 +1114,20 @@ class MixinStrUnicodeUserStringTest: self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(ValueError, '%10', '__mod__', (42,)) + if _testcapi.PY_SSIZE_T_MAX < sys.maxint: + self.checkraises(OverflowError, '%*s', '__mod__', + (_testcapi.PY_SSIZE_T_MAX + 1, '')) + if _testcapi.INT_MAX < sys.maxint: + self.checkraises(OverflowError, '%.*f', '__mod__', + (_testcapi.INT_MAX + 1, 1. / 7)) + # Issue 15989 + if 1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1) <= sys.maxint: + self.checkraises(OverflowError, '%*s', '__mod__', + (1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1), '')) + if _testcapi.UINT_MAX < sys.maxint: + self.checkraises(OverflowError, '%.*f', '__mod__', + (_testcapi.UINT_MAX + 1, 1. / 7)) + class X(object): pass self.checkraises(TypeError, 'abc', '__mod__', X()) |