diff options
author | Sean Gillespie <sean@swgillespie.me> | 2020-05-27 15:22:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-27 15:22:07 (GMT) |
commit | 29a1384c040d39659e7d01f1fd7b6eb71ef2634e (patch) | |
tree | 2862b50fdccfc415d6f03f6d60d26176749c6699 /Lib/ctypes/test | |
parent | fe2978b3b940fe2478335e3a2ca5ad22338cdf9c (diff) | |
download | cpython-29a1384c040d39659e7d01f1fd7b6eb71ef2634e.zip cpython-29a1384c040d39659e7d01f1fd7b6eb71ef2634e.tar.gz cpython-29a1384c040d39659e7d01f1fd7b6eb71ef2634e.tar.bz2 |
bpo-13097: ctypes: limit callback to 1024 arguments (GH-19914)
ctypes now raises an ArgumentError when a callback
is invoked with more than 1024 arguments.
The ctypes module allocates arguments on the stack in
ctypes_callproc() using alloca(), which is problematic
when large numbers of arguments are passed. Instead
of a stack overflow, this commit raises an ArgumentError
if more than 1024 parameters are passed.
Diffstat (limited to 'Lib/ctypes/test')
-rw-r--r-- | Lib/ctypes/test/test_callbacks.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index f622093..937a06d 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -287,6 +287,21 @@ class SampleCallbacksTestCase(unittest.TestCase): self.assertEqual(s.second, check.second) self.assertEqual(s.third, check.third) + def test_callback_too_many_args(self): + def func(*args): + return len(args) + + CTYPES_MAX_ARGCOUNT = 1024 + proto = CFUNCTYPE(c_int, *(c_int,) * CTYPES_MAX_ARGCOUNT) + cb = proto(func) + args1 = (1,) * CTYPES_MAX_ARGCOUNT + self.assertEqual(cb(*args1), CTYPES_MAX_ARGCOUNT) + + args2 = (1,) * (CTYPES_MAX_ARGCOUNT + 1) + with self.assertRaises(ArgumentError): + cb(*args2) + + ################################################################ if __name__ == '__main__': |