Skip to content

Conversation

@lindsaycode05
Copy link

Fixes #61362

Summary

  • After a Buffer backed by the internal pool has its ArrayBuffer detached (e.g. via ArrayBuffer.prototype.transfer()), subsequent Buffer.from(..., 'base64') calls would throw ERR_BUFFER_OUT_OF_BOUNDS. This change ensures pooled Buffer creation doesn’t rely on a detached pool ArrayBuffer.

Repro

const base64 = Buffer.from('hello', 'utf8').toString('base64');
const first = Buffer.from(base64, 'base64');
first.buffer.transfer();
Buffer.from(base64, 'base64'); // threw `ERR_BUFFER_OUT_OF_BOUNDS` before, succeeds now

Changes

  • Add a pool-detachment guard before pooled allocations.
  • Add a regression test for pooled base64 Buffer.from after transfer.

Tests

  • python3 tools/test.py test/parallel/test-buffer-pool-untransferable.js
  • make -j4 test

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. labels Jan 13, 2026
const base64 = 'aGVsbG8='; // "hello"
const buf = Buffer.from(base64, 'base64');
buf.buffer.transfer();
assert.strictEqual(buf.buffer.byteLength, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer should not be transferrable at all... This still transfers the underlying buffer.

@ChALkeR
Copy link
Member

ChALkeR commented Jan 13, 2026

This just masks the issue.

const base64 = Buffer.from('hello', 'utf8').toString('base64');
const first = Buffer.from(base64, 'base64');
first.buffer.transfer();

this could have corrupted other buffers allocated prior to first, not just the ones allocated after that

> 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
Destroying operations on pooled Buffer .buffer are the problem here, not just the future buffer allocs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can not construct Buffer after different Buffer was previously transfererd

4 participants