buffer: recreate pooled ArrayBuffer after transfer#61364
buffer: recreate pooled ArrayBuffer after transfer#61364lindsaycode05 wants to merge 1 commit intonodejs:mainfrom
Conversation
| const base64 = 'aGVsbG8='; // "hello" | ||
| const buf = Buffer.from(base64, 'base64'); | ||
| buf.buffer.transfer(); | ||
| assert.strictEqual(buf.buffer.byteLength, 0); |
There was a problem hiding this comment.
The buffer should not be transferrable at all... This still transfers the underlying buffer.
|
This just masks the issue.
this could have corrupted other buffers allocated prior to > x = Buffer.from('hello')
<Buffer 68 65 6c 6c 6f>
> y = Buffer.from('world')
<Buffer 77 6f 72 6c 64>
> y.buffer.transfer()
> x
<Buffer >
> Which could also include buffers allocated by Node.js internally |
|
Thanks for the PR! Ultimately, I think #61372 is the correct approach here. As Nikita mentioned, this doesn't really solve the underlying issue. |
|
Thanks guys, that makes sense. Given the broader semantics (detaching a shared backing store invalidates all views), my PR isn’t the right, long-term fix. I’ll leave it to #61372 and maintainer direction from here. Appreciate the discussion and pointers! Feel free to close this PR whenever convenient. |
Fixes #61362
Summary
ArrayBuffer.prototype.transfer()), subsequentBuffer.from(..., 'base64')calls would throwERR_BUFFER_OUT_OF_BOUNDS. This change ensures pooled Buffer creation doesn’t rely on a detached pool ArrayBuffer.Repro
Changes
Buffer.fromafter transfer.Tests
python3 tools/test.py test/parallel/test-buffer-pool-untransferable.jsmake -j4 test