diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-17 07:13:03 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2019-05-17 07:13:03 (GMT) |
commit | 14514d9084a40f599c57da853a305aa264562a43 (patch) | |
tree | 36cb61b74dbfda9ce1cdf72a864b640d0bda546d /Lib/ctypes | |
parent | 870b035bc6da96689b59dd6f79782ec6f1873617 (diff) | |
download | cpython-14514d9084a40f599c57da853a305aa264562a43.zip cpython-14514d9084a40f599c57da853a305aa264562a43.tar.gz cpython-14514d9084a40f599c57da853a305aa264562a43.tar.bz2 |
bpo-36946: Fix possible signed integer overflow when handling slices. (GH-13375)
The final addition (cur += step) may overflow, so use size_t for "cur".
"cur" is always positive (even for negative steps), so it is safe to use
size_t here.
Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
Diffstat (limited to 'Lib/ctypes')
-rw-r--r-- | Lib/ctypes/test/test_arrays.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py index 0fc5d7e..87ecbf0 100644 --- a/Lib/ctypes/test/test_arrays.py +++ b/Lib/ctypes/test/test_arrays.py @@ -69,6 +69,17 @@ class ArrayTestCase(unittest.TestCase): from operator import delitem self.assertRaises(TypeError, delitem, ca, 0) + def test_step_overflow(self): + a = (c_int * 5)() + a[3::sys.maxsize] = (1,) + self.assertListEqual(a[3::sys.maxsize], [1]) + a = (c_char * 5)() + a[3::sys.maxsize] = b"A" + self.assertEqual(a[3::sys.maxsize], b"A") + a = (c_wchar * 5)() + a[3::sys.maxsize] = u"X" + self.assertEqual(a[3::sys.maxsize], u"X") + def test_numeric_arrays(self): alen = 5 |