Repository navigation
Skip zero-byte copies when restoring a startup snapshot - #8590
Conversation
A Worker's top level that keeps an empty typed array over an ArrayBuffer of its own, such as `new Uint8Array(new ArrayBuffer(0))`, fails UBSan when a Worker starts from the snapshot. V8's serializer writes the off-heap backing store of a typed array even when it is empty, and on restore `BackingStore::Allocate()` gives a zero-byte store whose data pointer is null, so `SnapshotByteSource::CopyRaw()` calls `memcpy()` with a null destination. In this patch a V8 patch makes `CopyRaw()` return early for zero bytes, which covers every caller, and `startup-snapshot-globals-test` gets a case whose top level keeps an empty and a non-empty typed array across the snapshot.
There was a problem hiding this comment.
Superseded by the review of
949e1f61.
This review, of 95915a64
✅ Approved — A small, well-scoped V8 patch that skips zero-byte copies, plus a test that round-trips empty and non-empty typed arrays through the snapshot. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The early return for number_of_bytes == 0 in CopyRaw() sits after the bounds DCHECK_LE and before memcpy(), so the null-destination memcpy() cannot happen. The patch follows the layout of the other V8 patches and is registered in order in build/deps/v8.MODULE.bazel. The new empty-typed-array test case is wired the same way in the .js file and the .wd-test config.
📝 Documentation: ✅ LGTM
The patch's commit message states the root cause and the reason for the fix clearly. The code comment describes the code as it is now.
Reviewed commit: 95915a64
There was a problem hiding this comment.
Superseded by the review of
37bf1ca2.
This review, of 949e1f61
✅ Approved — A small, well-scoped V8 patch that skips zero-byte copies, plus a test that round-trips empty and non-empty typed arrays through the snapshot. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The early return for number_of_bytes == 0 in CopyRaw() sits after the bounds DCHECK_LE and before memcpy(), so the null-destination memcpy() cannot happen. The patch follows the layout of the other V8 patches and is registered in order in build/deps/v8.MODULE.bazel. The new empty-typed-array test case is wired the same way in the .js file and the .wd-test config.
📝 Documentation: ✅ LGTM
The patch's commit message states the root cause and the reason for the fix clearly. The code comment describes the code as it is now.
Reviewed commit: 949e1f61 — same changes as 95915a64, so this is that commit's review (no new review was run; line numbers are as of 95915a64)
…-v8-snapshot-empty-typed-array # Conflicts: # src/workerd/api/tests/startup-snapshot-globals-test.js
There was a problem hiding this comment.
✅ Approved — This is a small, well-scoped V8 patch that skips zero-byte copies in CopyRaw(), plus a test that keeps an empty and a non-empty typed array across the snapshot. The merge-conflict resolution since the last review keeps the test case intact, and there are no findings.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The merge-conflict resolution in src/workerd/api/tests/startup-snapshot-globals-test.js keeps the empty-typed-array case working:
- The
MODEcase, thetypedArraysreport field and the assertion handler are all still there. deepStrictEqualis imported.- The
.wd-testfile defines both the binding and the worker for the case.
The V8 patch adds an early return for zero bytes after the DCHECK_LE bounds check and before memcpy(), so memcpy() is never called with a null destination. The patch is listed in order in build/deps/v8.MODULE.bazel.
📝 Documentation: ✅ LGTM
The patch's commit message explains the root cause and the fix. The code comments describe the code as it is now.
Reviewed commit: 37bf1ca2
Blocks #8521: with Rust resources in the startup snapshot,
node:httpWorkers now boot from the snapshot, and the asan job fails inhttp-client-ts@all-autogates:V8 writes an empty typed array's off-heap backing store into the snapshot (the
ArrayBufferpath skips empty ones). On restore,BackingStore::Allocate(0)gives a null data pointer, soSnapshotByteSource::CopyRaw()callsmemcpy(nullptr, src, 0). Any Worker whose top level keeps one, likenew Uint8Array(new ArrayBuffer(0)), hits it.The V8 patch makes
CopyRaw()return early for zero bytes, andstartup-snapshot-globals-testgets a case that keeps an empty and a non-empty typed array across the snapshot.