Skip to content

GH-50831: [Python] Avoid aborting on read-only output buffers - #50833

Open
erichanwang wants to merge 1 commit into
apache:mainfrom
erichanwang:fix/output-stream-readonly-buffer
Open

GH-50831: [Python] Avoid aborting on read-only output buffers#50833
erichanwang wants to merge 1 commit into
apache:mainfrom
erichanwang:fix/output-stream-readonly-buffer

Conversation

@erichanwang

@erichanwang erichanwang commented Aug 9, 2026

Copy link
Copy Markdown

Rationale for this change

pa.output_stream() currently aborts the Python process when passed a read-only buffer such as pa.py_buffer(b'x') or a memoryview, because the C++ fixed-size buffer writer checks buffer->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 to FixedSizeBufferWriter is mutable and raise a Python ValueError before 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 pyarrow IO regression tests were added for the read-only buffer path and the valid mutable-buffer path. The local Arrow checkout also passes git 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.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

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?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

After updating the title, you can mark the pull request as ready for review.

See also:

@github-actions
github-actions Bot marked this pull request as draft August 9, 2026 00:48
@erichanwang erichanwang changed the title ARROW-50831 avoid abort on read-only output buffer GH-50831: [Python] Avoid aborting on read-only output buffers Aug 9, 2026
@erichanwang
erichanwang marked this pull request as ready for review August 9, 2026 01:07

@Reranko05 Reranko05 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you follow the Arrow PR desc template and edit the PR desc accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] pa.output_stream() aborts the process on a read-only buffer

2 participants