GH-51042: [Python] Reject invalid Arrow wrapper types - #51163
Open
1fanwang wants to merge 1 commit into
Open
Conversation
Generated-by: GitHub Copilot CLI (GPT-5.6 Sol) Signed-off-by: 1fanwang <1fannnw@gmail.com>
|
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes directly address the reported segfaults by enforcing wrapper-type validation at the Cython boundary and add targeted regression tests for each affected API.
Pull request overview
This PR hardens several PyArrow entry points (Parquet read options, sparse tensor conversion, Substrait serialization, and compute IndexOptions) against invalid wrapper arguments that previously could propagate null native pointers into C++ and crash the interpreter; invalid inputs now raise TypeError instead.
Changes:
- Add explicit wrapper-type validation for Parquet
binary_typein both dataset and parquet reader paths. - Enforce
Tensor,Schema, andScalarwrapper types at key Cython boundaries (sparsefrom_tensor, Substrait serialization, andIndexOptions). - Add focused regression tests covering the previously-crashing invalid inputs.
File summaries
| File | Description |
|---|---|
| python/pyarrow/_parquet.pyx | Reject non-DataType binary_type before unwrapping and native calls. |
| python/pyarrow/_dataset_parquet.pyx | Reject non-DataType binary_type in ParquetReadOptions setter. |
| python/pyarrow/_compute.pyx | Require Scalar for IndexOptions / _set_options to prevent invalid unwraps. |
| python/pyarrow/tensor.pxi | Require Tensor for sparse from_tensor conversions across sparse tensor types. |
| python/pyarrow/_substrait.pyx | Require Schema for Substrait serialize_schema / serialize_expressions. |
| python/pyarrow/tests/test_dataset.py | Add regression test for ParquetReadOptions(binary_type=0) raising TypeError. |
| python/pyarrow/tests/parquet/test_parquet_file.py | Add regression test for ParquetFile(..., binary_type=0) raising TypeError. |
| python/pyarrow/tests/test_compute.py | Add regression test for IndexOptions(0) raising TypeError. |
| python/pyarrow/tests/test_sparse_tensor.py | Add regression test ensuring sparse from_tensor(0) raises TypeError. |
| python/pyarrow/tests/test_substrait.py | Add regression tests for Substrait serialization rejecting invalid schema inputs. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Several PyArrow APIs accept values that are not the documented Arrow wrapper type, pass a null native pointer into C++, and terminate the Python process. Invalid inputs should raise
TypeError.Fixes #51042.
What changes are included in this PR?
The affected Parquet, sparse tensor, Substrait, and compute option entry points now validate their wrapper objects before native calls. The same guard covers the matching sibling APIs.
Are these changes tested?
The reported calls were run independently against PyArrow 25.0.1, then covered by focused tests against the patched source.
Raw logs
Are there any user-facing changes?
Yes. Invalid wrapper arguments now raise
TypeErrorinstead of crashing the interpreter.