-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: mark pool ArrayBuffer as untransferable
This removes a footgun in which users could attempt to transfer the pooled ArrayBuffer underlying a regular `Buffer`, which would lead to all `Buffer`s that share the same pool being rendered unusable as well, and potentially break creation of new pooled `Buffer`s. This disables this kind of transfer. Refs: #32752 PR-URL: #32759 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const { MessageChannel } = require('worker_threads'); | ||
|
||
// Make sure that the pools used by the Buffer implementation are not | ||
// transferable. | ||
// Refs: https://github.com/nodejs/node/issues/32752 | ||
|
||
const a = Buffer.from('hello world'); | ||
const b = Buffer.from('hello world'); | ||
assert.strictEqual(a.buffer, b.buffer); | ||
const length = a.length; | ||
|
||
const { port1 } = new MessageChannel(); | ||
port1.postMessage(a, [ a.buffer ]); | ||
|
||
// Verify that the pool ArrayBuffer has not actually been transfered: | ||
assert.strictEqual(a.buffer, b.buffer); | ||
assert.strictEqual(a.length, length); |