mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: disallow file-backed blob cloning
Disallow cloning of file-backed Blobs. If necessary, we can enable this later but for now we disable it. The reason is because the underlying FdEntry ends up bound to the Environment/Realm under which is was created and transfering across worker threads ends up failing. Fixes: https://github.com/nodejs/node/issues/47334 PR-URL: https://github.com/nodejs/node/pull/47574 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
86a8335a06
commit
595b2b3fd2
2 changed files with 22 additions and 1 deletions
|
@ -56,6 +56,7 @@ const {
|
|||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_INVALID_THIS,
|
||||
ERR_INVALID_STATE,
|
||||
ERR_BUFFER_TOO_LARGE,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
|
@ -74,6 +75,7 @@ const { queueMicrotask } = require('internal/process/task_queues');
|
|||
const kHandle = Symbol('kHandle');
|
||||
const kType = Symbol('kType');
|
||||
const kLength = Symbol('kLength');
|
||||
const kNotCloneable = Symbol('kNotCloneable');
|
||||
|
||||
const disallowedTypeCharacters = /[^\u{0020}-\u{007E}]/u;
|
||||
|
||||
|
@ -186,6 +188,11 @@ class Blob {
|
|||
}
|
||||
|
||||
[kClone]() {
|
||||
if (this[kNotCloneable]) {
|
||||
// We do not currently allow file-backed Blobs to be cloned or passed across
|
||||
// worker threads.
|
||||
throw new ERR_INVALID_STATE.TypeError('File-backed Blobs are not cloneable');
|
||||
}
|
||||
const handle = this[kHandle];
|
||||
const type = this[kType];
|
||||
const length = this[kLength];
|
||||
|
@ -438,7 +445,9 @@ function createBlobFromFilePath(path, options) {
|
|||
return lazyDOMException('The blob could not be read', 'NotReadableError');
|
||||
}
|
||||
const { 0: blob, 1: length } = maybeBlob;
|
||||
return createBlob(blob, length, options?.type);
|
||||
const res = createBlob(blob, length, options?.type);
|
||||
res[kNotCloneable] = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue