Skip to content
Open
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 @@ -217,6 +217,13 @@ def test_python_file_readinto():
assert len(dst_buf) == length


@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)


def test_python_file_read_buffer():
length = 10
data = b'0123456798'
Expand Down