-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: throw when filling with empty buffers #18129
Conversation
doc/api/buffer.md
Outdated
@@ -519,6 +519,10 @@ changes: | |||
pr-url: https://github.com/nodejs/node/pull/17427 | |||
description: Specifying an invalid string for `fill` triggers a thrown | |||
exception. | |||
- version: REPLACEME |
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.
Bad indentation (ditto below). This should also come first in changes
.
Buffer.alloc(1, Buffer.alloc(0)); | ||
}, { | ||
code: 'ERR_INVALID_ARG_VALUE', | ||
type: TypeError |
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.
This issue seems to be everywhere ERR_INVALID_ARG_VALUE
is used, so consider this non-blocking, but I'd think TypeError
is the wrong error to use here. The type of the argument (Buffer
) is fine. It's the value that's the problem. I think it should be vanilla Error
or maybe RangeError
.
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.
To your point, this PR uses the same error handling logic from #17427. In that PR, I was against using a TypeError
for the same reasons you list here, but other collaborators felt differently.
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.
I think TypeError
is fine here.
Prior to this commit, Node would enter an infinite loop when attempting to fill a non-zero length buffer with a zero length buffer. This commit introduces a thrown exception in this scenario. PR-URL: nodejs#18129 Fixes: nodejs#18128 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit reorders the function level changelogs of Buffer.prototype.fill() and Buffer.alloc() to reflect the order in which the entries were added. PR-URL: nodejs#18129 Fixes: nodejs#18128 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This does not land cleanly on v9.x cleanly. Can you please submit a PR against v9.x-staging |
This shouldn’t be backported, it’s a breaking change |
Prior to this commit, Node would enter an infinite loop when attempting to fill a non-zero length buffer with a zero length buffer. This commit introduces a thrown exception in this scenario.
Fixes: #18128
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)