Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/pyarrow/io.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ cdef class NativeFile(_Weakrefable):
handle = self.get_input_stream()

py_buf = py_buffer(b)
if not py_buf.buffer.get().is_mutable():
raise TypeError("readinto() argument must be a writable buffer")
buf_len = py_buf.size
buf = py_buf.buffer.get().mutable_data()

Expand Down
7 changes: 7 additions & 0 deletions python/pyarrow/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,13 @@ def test_nativefile_write_memoryview():
assert buf.to_pybytes() == data * 3


@pytest.mark.parametrize("dst_buf", [b"a", memoryview(b"a")])
def test_native_file_readinto_rejects_readonly_buffer(dst_buf):
with pa.BufferReader(b"x") as f:
with pytest.raises(TypeError, match="writable buffer"):
f.readinto(dst_buf)


# ----------------------------------------------------------------------
# Mock output stream

Expand Down