← Back to Pull requests

Read into a lazily committed buffer in metadata-read-overflow #8554

Closed
unknown closed this pull request without merging on Nov 17, 2026 19:33 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 18:13 UTC
Author

metadata-read-overflow guards the fix in 66802b6f3. PyodideMetadataReader::read() used to narrow the destination buffer's size to int, so a buffer of 2 GiB or more gave memcpy a negative length. The test got a buffer that large to the reader through compileModuleFromReadOnlyFS() with an inflated usedBytes. That call allocates a buffer of that size, zero-fills it and hands it to the Wasm compiler, three times. On bazelflare's 8 GiB executors that peaks around 8.6 GB, and the 0.28.2 variant is already OOM-killed (Killed in the log of the "before" run).

The test now reads through FS.read() into views of a WebAssembly.Memory. Its pages become resident only when written, and the reader writes only the file's 11 bytes. The reader still receives buffers of 0x7FFFFFFF, 0x80000000 and 0x80000001 bytes. A resizable ArrayBuffer doesn't work for this: jsg::asBytes() copies a view of one, so the reader would write into a 2 GiB heap copy. The test also asserts the byte count and the bytes read. The old test ignored every exception and only checked for a crash.

With the buffers gone, the no-tsan tag is removed.

Peak RSS (workerd VmHWM, bazelflare executors)

| variant | before | after | after, TSan | hello (for comparison) | hello, TSan |
| --- | --- | --- | --- | --- | --- |
| development | 8.62 GB | 0.27 GB | 0.83 GB | 0.27 GB | 0.82 GB |
| 0.26.0a2 | 4.47 GB | 0.30 GB | 1.01 GB | 0.32 GB | 1.05 GB |
| 0.28.2 | 8.29 GB (OOM-killed) | 0.27 GB | 0.88 GB | | |
| 314.0.6 | 8.62 GB | 0.29 GB | 0.82 GB | | |

The test now costs the same as hello. Under TSan, the ~1 GB for 0.26.0a2 is what any Pyodide test costs there.

Testing

Everything below ran on bazelflare (--config=bazelflare, --config=bazelflare-tsan):

  • All four variants pass, plus their @gc-stress variants, and the four under TSan.

  • //src/workerd/server/tests/python:all: 132/132 pass.

  • With the old int narrowing put back into readToTarget(), all four variants segfault in memcpy, so the test still catches the bug.
  • Peak RSS was measured with a --run_under bash wrapper that polls VmHWM of the workerd processes. The executor image has no python3 or GNU time.

    🤖 Generated with Claude Code

    Diff: 285 lines (+213 / -72) across 3 files Reviewer: hoodmane Review duration: 80m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 285 lines diff across 3 files
    0.40
    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.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8554"
    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.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    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.7% · Safe to merge
    15.7%