Skip to content
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

buffer.fill inconsistency for large (>2^31 bytes) buffers #35609

Closed
yehiyam opened this issue Oct 12, 2020 · 2 comments
Closed

buffer.fill inconsistency for large (>2^31 bytes) buffers #35609

yehiyam opened this issue Oct 12, 2020 · 2 comments
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@yehiyam
Copy link
Contributor

yehiyam commented Oct 12, 2020

  • v14.8.0:
  • Linux 5.3.7-050307-generic #201910180652 SMP Fri Oct 18 10:56:47 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux:
  • Buffer:

What steps will reproduce the bug?

There is an inconsistency between calling Buffer.alloc(size, fill) and calling let b=Buffer.alloc(size) and b.fill(fill)
According to the spec size can be any integer smaller than buffer.constants.MAX_LENGTH, which on my machine is just under 4GB.
When allocating a buffer of size larger than 2^31-1 using Buffer.alloc(size, fill) it throws ERR_OUT_OF_RANGE

let b = Buffer.alloc(2200000000,1)

Uncaught: RangeError [ERR_OUT_OF_RANGE]: The value of "end" is out of range. It must be >= 0 && <= 2200000000. Received 2200000000

But when split into two lines it doesn't throw

let b = Buffer.alloc(2200000000)
b.fill(1)

Also, if offset and end are provided to fill, the same error occures

let b = Buffer.alloc(2200000000)
b.fill(1,0,b.length)

Uncaught: RangeError [ERR_OUT_OF_RANGE]: The value of "end" is out of range. It must be >= 0 && <= 2200000000. Received 2200000000

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

At a minimum, to be consistent.
If buffer max size can be larger than 2^31-1, than it should be possible to fill it

What do you see instead?

Additional information

@ronag
Copy link
Member

ronag commented Oct 12, 2020

@addaleax maybe?

@addaleax addaleax added the buffer Issues and PRs related to the buffer subsystem. label Oct 12, 2020
@addaleax
Copy link
Member

#35134 already fixed this and has been released in newer versions of Node 14, so I’ll close this as there’s nothing more that can be done on our side. Updating Node.js should resolve this.

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.
Projects
None yet
Development

No branches or pull requests

3 participants