← Back to Pull requests

Zero native buffers before V8 copies a string into them #8443

Closed
unknown closed this pull request without merging on Nov 16, 2026 19:00 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 19:37 UTC
Author

This zero-fills the native buffers that string contents are copied into before they are handed to V8.

v8::String::Write() and WriteOneByte() return nothing, so a caller has to assume that every element it asked for was copied. That does not hold for a string corrupted inside the V8 sandbox: for a cons string whose two halves are the same string, V8 copies the halves and returns, whatever length the cons string itself claims. A buffer of uninitialized native memory then keeps its previous contents past that point, and they are encoded as if they were string data.

The buffers that were handed over uninitialized are now zeroed first:

the Latin-1 and UTF-16 staging buffers of TextEncoder.encode()
the chunk buffer of TextEncoderStream
the chunk buffer of DigestStream's well-formed string encoder
JsString::toArray(), used by btoa()

  • the UBSan-only temporary of a UTF-16 Buffer write
  • Buffers declared with KJ_STACK_ARRAY are already zeroed, and destinations inside the sandbox need nothing. JsString::writeInto() now documents the requirement for future callers.

    string-sandbox-test forges such a string by writing its length field, fills the stack and heap with a marker, and checks that toArray(), TextEncoder.encode() (one-byte and two-byte) and the DigestStream encoder return zeros past the copied halves, for a stack-staged and a heap-staged length. Each check fails without the corresponding fill. TextEncoderStream and the UBSan-only Buffer path have no test.

    The cost is one extra pass over the staging buffer per call. This is independent of #8412 and #8441, which deal with the string length being read twice, and touches lines next to theirs in encoding.c++.

    Diff: 215 lines (+161 / -54) across 2 files Reviewer: nathanwhit Review duration: 4283m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 215 lines diff across 2 files
    0.37
    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.322
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8443"
    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: 36.6% (MEDIUM) · Higher = larger blast radius
    36.6%
    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: 14.5% · Safe to merge
    14.5%