Zero native buffers before V8 copies a string into them #8443
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
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.322
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8443"
general
weight: 0.35
nathanwhit
This zero-fills the native buffers that string contents are copied into before they are handed to V8.
v8::String::Write()andWriteOneByte()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
TextEncoderStreamthe chunk buffer of
DigestStream's well-formed string encoderJsString::toArray(), used bybtoa()BufferwriteBuffers declared with
KJ_STACK_ARRAYare already zeroed, and destinations inside the sandbox need nothing.JsString::writeInto()now documents the requirement for future callers.string-sandbox-testforges such a string by writing its length field, fills the stack and heap with a marker, and checks thattoArray(),TextEncoder.encode()(one-byte and two-byte) and theDigestStreamencoder return zeros past the copied halves, for a stack-staged and a heap-staged length. Each check fails without the corresponding fill.TextEncoderStreamand the UBSan-onlyBufferpath 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++.