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 44864d7

Browse filesBrowse files
committed
worker: do not crash when JSTransferable lists untransferable value
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ed72d83 commit 44864d7
Copy full SHA for 44864d7

File tree

Expand file treeCollapse file tree

2 files changed

+45
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+45
-5
lines changed
Open diff view settings
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,20 @@ class SerializerDelegate : public ValueSerializer::Delegate {
367367

368368
private:
369369
Maybe<bool> WriteHostObject(BaseObjectPtr<BaseObject> host_object) {
370+
BaseObject::TransferMode mode = host_object->GetTransferMode();
371+
if (mode == BaseObject::TransferMode::kUntransferable) {
372+
ThrowDataCloneError(env_->clone_unsupported_type_str());
373+
return Nothing<bool>();
374+
}
375+
370376
for (uint32_t i = 0; i < host_objects_.size(); i++) {
371377
if (host_objects_[i] == host_object) {
372378
serializer->WriteUint32(i);
373379
return Just(true);
374380
}
375381
}
376382

377-
BaseObject::TransferMode mode = host_object->GetTransferMode();
378-
if (mode == BaseObject::TransferMode::kUntransferable) {
379-
ThrowDataCloneError(env_->clone_unsupported_type_str());
380-
return Nothing<bool>();
381-
} else if (mode == BaseObject::TransferMode::kTransferable) {
383+
if (mode == BaseObject::TransferMode::kTransferable) {
382384
// TODO(addaleax): This message code is too specific. Fix that in a
383385
// semver-major follow-up.
384386
THROW_ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST(env_);
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Flags: --expose-internals --no-warnings
2+
'use strict';
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const {
6+
JSTransferable, kTransfer, kTransferList
7+
} = require('internal/worker/js_transferable');
8+
const { MessageChannel } = require('worker_threads');
9+
10+
// Transferring a JSTransferable that refers to another, untransferable, value
11+
// in its transfer list should not crash hard.
12+
13+
class OuterTransferable extends JSTransferable {
14+
constructor() {
15+
super();
16+
// Create a detached MessagePort at this.inner
17+
const c = new MessageChannel();
18+
this.inner = c.port1;
19+
c.port2.postMessage(this.inner, [ this.inner ]);
20+
}
21+
22+
[kTransferList] = common.mustCall(() => {
23+
return [ this.inner ];
24+
});
25+
26+
[kTransfer] = common.mustCall(() => {
27+
return {
28+
data: { inner: this.inner },
29+
deserializeInfo: 'does-not:matter'
30+
};
31+
});
32+
}
33+
34+
const { port1 } = new MessageChannel();
35+
const ot = new OuterTransferable();
36+
assert.throws(() => {
37+
port1.postMessage(ot, [ot]);
38+
}, { name: 'DataCloneError' });

0 commit comments

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