-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
fix: support buffers greater than 2^32
bytes in length in Buffer.concat
and Buffer.copy
#55492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { kMaxLength } = require('buffer'); | ||
|
||
const zero = []; | ||
const one = [ Buffer.from('asdf') ]; | ||
|
@@ -98,3 +99,15 @@ assert.deepStrictEqual( | |
assert.deepStrictEqual(Buffer.concat([new Uint8Array([0x41, 0x42]), | ||
new Uint8Array([0x43, 0x44])]), | ||
Buffer.from('ABCD')); | ||
|
||
// Ref: https://github.com/nodejs/node/issues/55422#issue-2594486812 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: please consider expanding the comment a bit here with a short summary of what is being tested for so folks don't have to necessarily follow the link to get the gist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it is better to have the description of the test inlined. However I was under the impression that the policy was to use refs? See #55492 (comment) where I actually removed the explanation at the request of another maintainer. |
||
if (2 ** 32 + 1 <= kMaxLength) { | ||
const a = Buffer.alloc(2 ** 31, 0); | ||
const b = Buffer.alloc(2 ** 31, 1); | ||
const c = Buffer.alloc(1, 2); | ||
const destin = Buffer.concat([a, b, c]); | ||
|
||
assert.deepStrictEqual(destin.subarray(0, 2 ** 31), a); | ||
assert.deepStrictEqual(destin.subarray(2 ** 31, 2 ** 32), b); | ||
assert.deepStrictEqual(destin.subarray(2 ** 32), c); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert here is a bit redundant given the checks that are made in the
copyImpl
call site.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this assert is useful since it makes
_copyActual
's invariant thatsource
andtarget
need to beUint8Array
explicit.It indicates to any future/new maintainers needing to call
_copyActual
what the invariants are. They don't have to guess at the invariants, or deduce the preconditions by exploring all the call-sites of_copyActual
.