This is an automated email from the ASF dual-hosted git repository.

jorisvandenbossche pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2ae6d11167 GH-41758: [Python] Disallow direct pa.RecordBatchReader() 
construction to avoid segfaults (#41773)
2ae6d11167 is described below

commit 2ae6d11167a9800b2a3d4cfdd968f2bd69f98183
Author: Joris Van den Bossche <[email protected]>
AuthorDate: Thu Jun 13 14:43:22 2024 +0200

    GH-41758: [Python] Disallow direct pa.RecordBatchReader() construction to 
avoid segfaults (#41773)
    
    ### Rationale for this change
    
    A user should never do this, but if you do you easily get segfaults. We 
should raise an error with an informative message like we do for other classes.
    
    ### Are these changes tested?
    Yes
    
    * GitHub Issue: #41758
    
    Authored-by: Joris Van den Bossche <[email protected]>
    Signed-off-by: Joris Van den Bossche <[email protected]>
---
 python/pyarrow/ipc.pxi            | 5 +++++
 python/pyarrow/tests/test_misc.py | 1 +
 2 files changed, 6 insertions(+)

diff --git a/python/pyarrow/ipc.pxi b/python/pyarrow/ipc.pxi
index 617e25a142..e15b0ea40e 100644
--- a/python/pyarrow/ipc.pxi
+++ b/python/pyarrow/ipc.pxi
@@ -659,6 +659,11 @@ cdef class RecordBatchReader(_Weakrefable):
 
     # cdef block is in lib.pxd
 
+    def __init__(self):
+        raise TypeError("Do not call {}'s constructor directly, "
+                        "use one of the RecordBatchReader.from_* functions 
instead."
+                        .format(self.__class__.__name__))
+
     def __iter__(self):
         return self
 
diff --git a/python/pyarrow/tests/test_misc.py 
b/python/pyarrow/tests/test_misc.py
index 308c37fd0d..3d8ab2999e 100644
--- a/python/pyarrow/tests/test_misc.py
+++ b/python/pyarrow/tests/test_misc.py
@@ -237,6 +237,7 @@ def test_set_timezone_db_path_non_windows():
     pa.StructScalar,
     pa.DictionaryScalar,
     pa.RunEndEncodedScalar,
+    pa.RecordBatchReader,
     pa.ipc.Message,
     pa.ipc.MessageReader,
     pa.MemoryPool,

Reply via email to