Conversation
63eb77c to
abfbdfe
Compare
lib/buffer.js
Outdated
There was a problem hiding this comment.
I think the extra set of parentheses can be dropped here.
lib/buffer.js
Outdated
There was a problem hiding this comment.
I think this can be all on one line as well?
lib/buffer.js
Outdated
There was a problem hiding this comment.
I believe it should be 'target' to match documentation and stack traces, and not 'otherBuffer'.
test/parallel/test-buffer-alloc.js
Outdated
test/parallel/test-buffer-copy.js
Outdated
There was a problem hiding this comment.
Is there a reason for the inconsistent capitalization between 'string' and 'Number'?
There was a problem hiding this comment.
(that above is a super-minor non-blocking nit, probably applies to lots of other errors in our code base, can be cleaned up later, but if you're feeling in a perfectionist mood...)
There was a problem hiding this comment.
That's the dark magic of ERR_INVALID_ARG_TYPE('targetStart', ['Number'], targetStart). I'm assuming it does .name to the types, and typeof val to the val...
Lines 674 to 699 in acb363f
Trott
left a comment
There was a problem hiding this comment.
LGTM for a fix for 11.x. Less sure about backporting to 10.x, but that can be to-be-determined.
|
This does not just affect |
|
(And, 👍 for considering this semver-patch for v11.x, 👎 to landing this on v10.x, ever, where it would still be semver-major.) |
/CC @nodejs/release. |
So that the release folks don't have to educate themselves on the entire history here in other issues etc.: Through Node.js 10.9.0: > var b = Buffer.allocUnsafe(1024)
undefined
> var c = Buffer.allocUnsafe(512)
undefined
> b.copy(c, '112', 600)
400
> After 10.9.0, the With this patch, it throws. I believe what @refack is saying is that the move from crash to throws is semver patch so can be landed/backported to the 10.x line. I believe what @addaleax is saying (and I'm inclined to agree) is that the crash was a regression and moving back to the behavior in 10.9.0 is the change that would be considered semver patch and not semver major. Moving on to throwing an error is a breaking change. So I believe that's what @refack is soliciting feedback on. FWIW, in 11.0.0, it crashes, so changing that to a throw in a subsequent 11.x release is semver patch. I'm mentioning it because it would not receive a semver major callout in the change log for 11.0.0, so a case could be made that it's not even semver patch there. (I disagree with that. If something never worked in a 11.x, then it's not a breaking change to fix it differently than in previous release lines. But others might feel differently or there might be a policy somewhere?) |
|
Since the previous behaviour was not completely broken (as the example with the number being passed as a string shows), I think we should revert it on v10.x (ideally before it transitions to LTS). |
lib/buffer.js
Outdated
There was a problem hiding this comment.
We should only use a default in case it's definitely not set. So I would write it as:
| if (val) { | |
| if (val != null) { |
lib/buffer.js
Outdated
There was a problem hiding this comment.
| throw new ERR_INVALID_ARG_TYPE(name, ['Number'], val); | |
| throw new ERR_INVALID_ARG_TYPE(name, 'number', val); |
This resolves https://github.com/nodejs/node/pull/23840/files#r227630142
lib/buffer.js
Outdated
There was a problem hiding this comment.
I suggest to replace this whole function with the validateUint32() function that we already have in the validators file. It will be a stricter check by also verifying that the input is an integer in the correct range.
2cdedd1 to
3fc87b4
Compare
|
@refack So … there’s also methods like I think the main options would be wrapping them (which might create some overhead we don’t want?), doing the typechecks in C++ in those methods, or incorporating something like #23795 into this PR. I’m fine with any of them, but I’d like us to do something, even if they are not technically public… |
Ok. |
|
@refack I guess I'd try to stay in JS if possible. |
|
I have an idea. Rename the unwrapped methods, and expose new wrapped methods with the old names. This way the documented API doesn't regress. |
|
@refack This is being worked on? (Should we add an |
Validate
buffer.copyarguments type and range.Since this fixes a crash in node11, it might be considered semver-patch.
Alternative to: #23795
Fixes: #23668
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes