[pypy-commit] pypy py3.7: Checking for overflow in ctypes array creation (fixing test.test_ctypes)

schoelle pypy.commits at gmail.com
Sat Nov 2 12:52:18 EDT 2019


Author: Bernd Schoeller <bernd at fams.de>
Branch: py3.7
Changeset: r97940:9f57693bca37
Date: 2019-11-02 16:45 +0000
http://bitbucket.org/pypy/pypy/changeset/9f57693bca37/

Log:	Checking for overflow in ctypes array creation (fixing
	test.test_ctypes)

diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -275,6 +275,8 @@
         raise TypeError("Can't multiply a ctypes type by a non-integer")
     if length < 0:
         raise ValueError("Array length must be >= 0")
+    if length * base._sizeofinstances() > sys.maxsize:
+        raise OverflowError("array too large")
     key = (base, length)
     try:
         return ARRAY_CACHE[key]


More information about the pypy-commit mailing list