Reject read-only destination buffers in read APIs #1121
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 256 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.332
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1121"
general
weight: 0.35
madsbk
Description
Reading into a read-only buffer currently succeeds and overwrites it:
CuFile.read(bytes(n))modifies thebytesobject, and a NumPy array withflags.writeable = Falsegets the file contents written into it.parse_buffer_argument()is shared by the read and write paths. It recordsArray.readonly, but it never checks that flag.This PR adds a
writableflag toparse_buffer_argument(). All destination call sites now set it:CuFilepread/read/read_async,Mmapread/preadandRemoteFileread/pread. A read-only destination now raisesValueError("Cannot read into a read-only buffer")before any I/O is submitted.ValueErrormatches the other checks in that function. Write paths keepwritable=False, so writing frombytesor from read-only arrays still works.The standard library rejects the same input:
io.FileIO.readinto(bytes(...))raisesTypeError.Tests
test_basic_io.py::test_read_into_readonly_buffer:-
CuFile.read/preadinto a read-only ndarray and intobytesnow raise, and the buffer stays unchanged.- Writing from a read-only array still works.
- Reading into a writable array still works.
test_mmap.py::test_read_into_readonly_buffer:Mmap.read/preadwith a read-only destination raise.Both new tests fail on
main("DID NOT RAISE") and pass with this change. The released 26.10 wheel shows the same behaviour:Mmap.read(bytes(4096))returns 4096 and thebytesobject then holds the file contents.test_basic_io.py,test_mmap.py,test_numpy.pyandtest_http_io.pypass with the change. The run was on x86_64 Linux with an NVIDIA Blackwell Ultra (sm_103) GPU, in compatibility mode.Checklist
This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.