summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-19 10:26:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-19 10:26:26 (GMT)
commit441d30fac7f4037e4a79e4ada873de3b6f6e5a26 (patch)
treea406cb41f1b78476445786f408b95b1cd0bdb7a6 /Lib/ctypes
parentff12fae80e15ad29ae2557d23e70f6ff9365b31f (diff)
downloadcpython-441d30fac7f4037e4a79e4ada873de3b6f6e5a26.zip
cpython-441d30fac7f4037e4a79e4ada873de3b6f6e5a26.tar.gz
cpython-441d30fac7f4037e4a79e4ada873de3b6f6e5a26.tar.bz2
Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks. This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/test/test_structures.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index b6d8b01..d764ce2 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -1,6 +1,7 @@
import unittest
from ctypes import *
from struct import calcsize
+import _testcapi
class SubclassesTest(unittest.TestCase):
def test_subclass(self):
@@ -199,6 +200,14 @@ class StructureTestCase(unittest.TestCase):
"_pack_": -1}
self.assertRaises(ValueError, type(Structure), "X", (Structure,), d)
+ # Issue 15989
+ d = {"_fields_": [("a", c_byte)],
+ "_pack_": _testcapi.INT_MAX + 1}
+ self.assertRaises(ValueError, type(Structure), "X", (Structure,), d)
+ d = {"_fields_": [("a", c_byte)],
+ "_pack_": _testcapi.UINT_MAX + 2}
+ self.assertRaises(ValueError, type(Structure), "X", (Structure,), d)
+
def test_initializers(self):
class Person(Structure):
_fields_ = [("name", c_char*6),