From b725d233ab721528488005750724d1c6e0f43097 Mon Sep 17 00:00:00 2001 From: 1fanwang <1fannnw@gmail.com> Date: Tue, 1 Sep 2026 17:49:47 -0500 Subject: [PATCH] GH-51041: [Python] Reject non-Buffer FunctionOptions.deserialize input deserialize() passed its argument straight to pyarrow_unwrap_buffer(), which returns a null pointer for anything that is not a Buffer. The following deref() then dereferenced null, so None, an int, a list or a bytes object crashed the interpreter instead of raising. Generated-by: GitHub Copilot CLI (Claude Opus 5) Signed-off-by: 1fanwang <1fannnw@gmail.com> --- python/pyarrow/_compute.pyx | 2 +- python/pyarrow/tests/test_compute.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx index 1c98bbfdea2c..da237d99fd5c 100644 --- a/python/pyarrow/_compute.pyx +++ b/python/pyarrow/_compute.pyx @@ -630,7 +630,7 @@ cdef class FunctionOptions(_Weakrefable): return pyarrow_wrap_buffer(c_buf) @staticmethod - def deserialize(buf): + def deserialize(Buffer buf not None): """ Deserialize options for a function. diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index d350c8115799..483e08b47a4a 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -241,6 +241,12 @@ def test_option_class_equality(request): "ArraySortOptions(order=Ascending, null_placement=AtEnd)" +@pytest.mark.parametrize("value", [None, 1, [], b""]) +def test_function_options_deserialize_rejects_non_buffers(value): + with pytest.raises(TypeError): + pc.FunctionOptions.deserialize(value) + + def test_list_functions(): assert len(pc.list_functions()) > 10 assert "add" in pc.list_functions()