From 4840f2bf291dfa58af123768a66b1a49e3af31a4 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Sun, 19 Jan 2020 10:23:34 +0100 Subject: Issue #440 Limit the amount of memory that is requested from alloca() for temporary conversion of arguments. Non-small requests are instead handled with PyObject_Malloc() and PyObject_Free(). --- testing/cffi0/test_function.py | 13 +++++++++++++ testing/cffi0/test_verify.py | 10 ++++++++++ testing/cffi1/test_recompiler.py | 10 ++++++++++ 3 files changed, 33 insertions(+) (limited to 'testing') diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py index d1f9ce4..6312707 100644 --- a/testing/cffi0/test_function.py +++ b/testing/cffi0/test_function.py @@ -520,3 +520,16 @@ class TestFunction(object): assert str(e.value).startswith("library '") assert str(e.value).endswith("' has already been closed") ffi.dlclose(lib) # does not raise + + def test_passing_large_list(self): + if self.Backend is CTypesBackend: + py.test.skip("the ctypes backend doesn't support this") + ffi = FFI(backend=self.Backend()) + ffi.cdef(""" + void getenv(char *); + """) + needs_dlopen_none() + m = ffi.dlopen(None) + arg = [b"F", b"O", b"O"] + [b"\x00"] * 20000000 + x = m.getenv(arg) + assert x is None diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py index 52ce214..3a1c0b9 100644 --- a/testing/cffi0/test_verify.py +++ b/testing/cffi0/test_verify.py @@ -2550,3 +2550,13 @@ def test_arithmetic_in_cdef(): """.replace('?', str(a))) # the verify() crashes if the values in the enum are different from # the values we computed ourselves from the cdef() + +def test_passing_large_list(): + ffi = FFI() + ffi.cdef("""void passing_large_list(long[]);""") + lib = ffi.verify(""" + static void passing_large_list(long a[]) { } + """) + arg = list(range(20000000)) + lib.passing_large_list(arg) + # assert did not segfault diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py index 1b837f8..78abaa0 100644 --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -2445,3 +2445,13 @@ def test_struct_with_func_with_struct_arg(): }; """) py.test.raises(RuntimeError, ffi.new, "struct BinaryTree *") + +def test_passing_large_list(): + ffi = FFI() + ffi.cdef("""void passing_large_list(long[]);""") + lib = verify(ffi, "test_passing_large_list", """ + static void passing_large_list(long a[]) { } + """) + arg = list(range(20000000)) + lib.passing_large_list(arg) + # assert did not segfault -- cgit v1.2.1