Skip to content

fix(ext/node): fix Buffer.concat truncating buffers larger than 4GB#32913

Merged
bartlomieju merged 1 commit intomainfrom
fix/buffer-concat-truncation-4gb
Mar 23, 2026
Merged

fix(ext/node): fix Buffer.concat truncating buffers larger than 4GB#32913
bartlomieju merged 1 commit intomainfrom
fix/buffer-concat-truncation-4gb

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Replace | 0 (32-bit integer truncation) with MathTrunc() in checked(), _allocUnsafe(), and fromString() in the Node.js Buffer polyfill
  • This fixes Buffer.concat and Buffer.allocUnsafe silently truncating buffers with sizes exceeding 2^32 (e.g. (2**32 + 5) | 05)

Closes #32895

Test plan

  • Added tests for Buffer.allocUnsafe and Buffer.concat with >4GB sizes (marked ignore: true due to memory requirements)
  • Existing buffer tests pass (./x test-node buffer)

🤖 Generated with Claude Code

The `checked()` function and `_allocUnsafe()` used `| 0` to truncate
lengths to integers, which converts numbers to 32-bit signed integers.
This caused any buffer size > 2^32 to wrap around (e.g. `(2**32 + 5) | 0`
becomes `5`). Replace `| 0` with `MathTrunc()` to support large buffers.

Closes #32895

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju merged commit c99c8ac into main Mar 23, 2026
112 checks passed
@bartlomieju bartlomieju deleted the fix/buffer-concat-truncation-4gb branch March 23, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer.concat truncates buffers larger than 4GB

1 participant