Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20dc172

Browse filesBrowse files
committed
worker: copy transferList ArrayBuffers on unknown allocator
If the `ArrayBuffer::Allocator` used to create `ArrayBuffer`s in the current `Isolate` is not a Node.js `ArrayBufferAllocator`, we cannot know that it is `malloc()`-based, an in particular it might not be compatible with the `ArrayBuffer::Allocator` on the receiving end of the connection. PR-URL: #26207 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Backport-PR-URL: #26302 Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 437bb25 commit 20dc172
Copy full SHA for 20dc172

File tree

Expand file treeCollapse file tree

1 file changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ MaybeLocal<Value> Message::Deserialize(Environment* env,
132132

133133
// Attach all transferred ArrayBuffers to their new Isolate.
134134
for (uint32_t i = 0; i < array_buffer_contents_.size(); ++i) {
135+
if (!env->isolate_data()->uses_node_allocator()) {
136+
// We don't use Node's allocator on the receiving side, so we have
137+
// to create the ArrayBuffer from a copy of the memory.
138+
AllocatedBuffer buf =
139+
env->AllocateManaged(array_buffer_contents_[i].size);
140+
memcpy(buf.data(),
141+
array_buffer_contents_[i].data,
142+
array_buffer_contents_[i].size);
143+
deserializer.TransferArrayBuffer(i, buf.ToArrayBuffer());
144+
continue;
145+
}
146+
135147
Local<ArrayBuffer> ab =
136148
ArrayBuffer::New(env->isolate(),
137149
array_buffer_contents_[i].release(),
@@ -288,8 +300,10 @@ Maybe<bool> Message::Serialize(Environment* env,
288300
Local<ArrayBuffer> ab = entry.As<ArrayBuffer>();
289301
// If we cannot render the ArrayBuffer unusable in this Isolate and
290302
// take ownership of its memory, copying the buffer will have to do.
291-
if (!ab->IsNeuterable() || ab->IsExternal())
303+
if (!ab->IsNeuterable() || ab->IsExternal() ||
304+
!env->isolate_data()->uses_node_allocator()) {
292305
continue;
306+
}
293307
if (std::find(array_buffers.begin(), array_buffers.end(), ab) !=
294308
array_buffers.end()) {
295309
ThrowDataCloneException(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.