GH-50831: [Python] Avoid aborting on read-only output buffers - #50833
GH-50831: [Python] Avoid aborting on read-only output buffers#50833erichanwang wants to merge 2 commits into
Conversation
|
Thanks for opening a pull request! This pull request has been automatically converted to a draft because its title doesn't match Arrow's required format. If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project. Then could you also rename the pull request title in the following format? or After updating the title, you can mark the pull request as ready for review. See also: |
Reranko05
left a comment
There was a problem hiding this comment.
Can you follow the Arrow PR desc template and edit the PR desc accordingly.
|
Updated the PR description to match Arrow |
|
Follow-up implementation update:
|
|
Updated the PR description to follow the Apache Arrow template. It now includes the required rationale, change summary, testing, and user-facing-change sections, along with the issue reference and critical-fix explanation. |
|
@/tmp/reply_arrow_50833.md |
Rationale for this change
pa.output_stream()currently aborts the Python process when passed a read-only buffer such aspa.py_buffer(b'x')or amemoryview, because the C++ fixed-size buffer writer checksbuffer->is_mutable(). A Python API misuse should raise a Python exception instead of terminating the interpreter.What changes are included in this PR?
python/pyarrow/io.pxi: validate that a buffer passed toFixedSizeBufferWriteris mutable and raise a PythonValueErrorbefore constructing the C++ writer.python/pyarrow/tests/test_io.py: add regression coverage for read-only buffers and preserve successful writes to mutable buffers.Fixes #50831.
Are these changes tested?
Yes. Focused
pyarrowIO regression tests were added for the read-only buffer path and the valid mutable-buffer path. The local Arrow checkout also passesgit diff --check; the available Arrow CI checks are passing.Are there any user-facing changes?
Yes. Passing a read-only buffer to
pa.output_stream()now raises a Python exception instead of aborting the process. Valid mutable-buffer behavior is unchanged.This PR contains a "Critical Fix". This fixes a bug that causes a crash when the API contract is upheld by passing a buffer object that is accepted by the Python API but is read-only.
pa.output_stream()aborts the process on a read-only buffer #50831