GH-51044: [Python] Reject read-only readinto destinations - #51126
Open
carrerasdarren-cell wants to merge 1 commit into
Open
GH-51044: [Python] Reject read-only readinto destinations#51126carrerasdarren-cell wants to merge 1 commit into
carrerasdarren-cell wants to merge 1 commit into
Conversation
Immutable destinations expose a null mutable pointer and can crash the native read path. Validate destination mutability and cover bytes and read-only memoryviews with regression tests. Assisted-by: OpenAI Codex
carrerasdarren-cell
requested review from
AlenkaF,
raulcd and
rok
as code owners
September 1, 2026 18:33
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
BufferReader.readinto()currently segfaults when passed a read-only destination such asbytesor a read-onlymemoryview.py_buffer()creates an immutable Arrow buffer,mutable_data()returns a null pointer, and the C++ read path attempts to copy into that pointer. A Python API misuse should raise a Python exception rather than terminate the interpreter.What changes are included in this PR?
NativeFile.readinto()destination is mutable before obtaining its writable pointer.TypeErrorfor immutable destinations.bytesand read-onlymemoryviewdestinations.Are these changes tested?
Yes. The focused
readintotests pass against a locally compiled patchedpyarrow.lib. The stock 25.0.1 wheel exits with status 139 for the issue reproducer, while the patched build raises the expectedTypeError; the writablebytearraycontrol continues to read successfully.Are there any user-facing changes?
Yes. Passing a read-only destination to
NativeFile.readinto()now raisesTypeErrorinstead of terminating the interpreter. Writable-buffer behavior is unchanged.Fixes #51044.
This contribution was developed with assistance from OpenAI Codex. I reviewed, tested, and take responsibility for the patch and this description.
BufferReader.readinto()segfaults on a read-only destination #51044