[Python] `pa.output_stream()` aborts the process on a read-only buffer
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
### Describe the bug, including details regarding any error messages, version, and platform.
I've been fuzzing Python C extension modules for a small research project, and this one came up. It reproduces with the binary wheel from a plain `pip install pyarrow`.
### Versions
pyarrow 25.0.0, CPython 3.12.3, Ubuntu 24.04 x86_64.
### Reproducer
```python
import pyarrow as pa
pa.output_stream(pa.py_buffer(b'x'))
```
The process aborts (SIGABRT, exit 134) after printing:
```
/arrow/cpp/src/arrow/io/memory.cc:165: Check failed: buffer->is_mutable() Must pass mutable buffer
[1] 3911118 IOT instruction (core dumped) python
```
`memoryview(b'')` and an empty `py_buffer` do the same:
```python
pa.output_stream(memoryview(b'')) # SIGABRT
pa.output_stream(pa.py_buffer(b'')) # SIGABRT
```
### What does work
A mutable buffer, a path, and `BufferOutputStream` are all fine:
```python
>>> b = pa.allocate_buffer(16)
>>> b.is_mutable
True
>>> type(pa.output_stream(b))
>>> type(pa.output_stream('/tmp/o.bin'))
```
And `pa.py_buffer` is documented to produce a read-only buffer:
```python
>>> pa.py_buffer(b'x').is_mutable
False
```
### Why I think it is worth reporting
`output_stream`'s own docstring lists `buffer` among the accepted source types:
```
source : str, Path, buffer, file-like object
The source to open for writing.
```
so passing a buffer is the documented usage, and a read-only one terminates the interpreter rather than raising.
---
This looks to me like a bug, but I'm not certain it is one, so I'm filing an issue.
### Component(s)
Python
Contributor guide
Assessment
This issue has not been assessed yet.