← Back to Pull requests

Reject read-only destination buffers in read APIs #1121

Closed
unknown closed this pull request without merging on Nov 16, 2026 09:10 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 20:58 UTC
Author

Description

Reading into a read-only buffer currently succeeds and overwrites it: CuFile.read(bytes(n)) modifies the bytes object, and a NumPy array with flags.writeable = False gets the file contents written into it. parse_buffer_argument() is shared by the read and write paths. It records Array.readonly, but it never checks that flag.

This PR adds a writable flag to parse_buffer_argument(). All destination call sites now set it: CuFile pread/read/read_async, Mmap read/pread and RemoteFile read/pread. A read-only destination now raises ValueError("Cannot read into a read-only buffer") before any I/O is submitted. ValueError matches the other checks in that function. Write paths keep writable=False, so writing from bytes or from read-only arrays still works.

The standard library rejects the same input: io.FileIO.readinto(bytes(...)) raises TypeError.

Tests

  • test_basic_io.py::test_read_into_readonly_buffer:

  • - CuFile.read/pread into a read-only ndarray and into bytes now 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/pread with 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 the bytes object then holds the file contents. test_basic_io.py, test_mmap.py, test_numpy.py and test_http_io.py pass with the change. The run was on x86_64 Linux with an NVIDIA Blackwell Ultra (sm_103) GPU, in compatibility mode.

    Checklist


  • I am familiar with the Contributing Guidelines.

  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

    Diff: 256 lines (+192 / -64) across 3 files Reviewer: madsbk Review duration: 2172m
    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
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%