Repository navigation
fix(ext/web): validate the transfer list before serializing and detach only on success - #37122
Open
Aschenbath wants to merge 1 commit into
Open
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
…h only on success Closes denoland#37105 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NetOpWibby
pushed a commit
to theende/ende
that referenced
this pull request
Nov 7, 2026
…h only on success
structuredClone(value, { transfer }) had side effects when it threw, and
checked the transfer list too late. op_serialize detached the transferred
ArrayBuffers before checking whether serialization succeeded, so a getter
that throws or a value that can't be cloned left the caller's buffers
detached. Entries that aren't transferable were rejected only after
serializing, so getters ran first and their exceptions replaced the
DataCloneError, and duplicate entries weren't rejected at all.
As StructuredSerializeWithTransfer requires, reject duplicate and
non-transferable entries first, then serialize, and detach only once
serialization has succeeded. On failure the buffers stay attached and
their backing stores are taken out of the store again.
Ende change: op_serialize also checks every transferred buffer before
registering any, so a non-detachable entry (a WebAssembly.Memory buffer)
no longer leaves the backing stores of the entries before it in the
store.
(cherry picked from commit 02f93cafd3e2589898723782ff03e5a630d24455)
Upstream: denoland/deno#37122
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #37105
structuredClone(value, { transfer })had side effects when it threw, and checked the transfer list too late:op_serializedetached the transferredArrayBuffers right afterwrite_value, before checking whether serialization succeeded. A getter that throws, or a value that can't be cloned, left the caller's buffers detached.serializeJsMessageDatarejected entries that aren't transferable (Value not transferable) only aftercore.serialize, so getters on the value ran first, and a getter's exception replaced theDataCloneError. ASharedArrayBufferin the list had the same problem.MessagePort.prototype.postMessagehas its own duplicate check, butstructuredClonedoesn't go through it.StructuredSerializeWithTransfer rejects duplicate and non-transferable entries first, then serializes, and transfers only after serialization succeeds.
Changes:
ext/web/13_message_port.js: the loop inserializeJsMessageDatathat already runs beforecore.serializenow also throwsDataCloneErrorfor a duplicate entry and for an entry that is neither anArrayBuffernor a host object. The message for the second is the sameValue not transferableas before, so the existingSharedArrayBuffertest still matches.libs/core/ops_builtin_v8.rs:op_serializedetaches the buffers only whenwrite_valuesucceeded and nothing was caught. On failure it leaves them attached and takes their backing stores back out ofshared_array_buffer_store.With this change, the reproduction in the issue prints exactly the expected output:
Testing
tests/unit/structured_clone_test.ts, covering the cases from the issue plus a successful transfer. Both fail onmainand pass with this change (denorebuilt for each run).unit::structured_clone_test,unit::message_channel_test,unit::worker_testandunit_node::worker_threads_testpass.tools/lint.js --jsand dprint check pass on the changed files, andcargo clippy -p deno_core -- -D warningsis clean.AI disclosure
This PR was written primarily by Claude Code (Claude Opus 5.5), including the change, the tests and this description. It has not yet been reviewed by a human.
🤖 Generated with Claude Code