fs: do basic arg validation of truncate in js#2498
fs: do basic arg validation of truncate in js#2498thefourtheye wants to merge 1 commit intonodejs:masterfrom
Conversation
|
Out of curiousity, what was the motivation behind these changes? |
b93d681 to
9910ba2
Compare
lib/fs.js
Outdated
There was a problem hiding this comment.
Just seeing the error message. If you want to ensure it is an integer, you can drop Number.isFinite and use Number.isInteger instead
There was a problem hiding this comment.
@targos Man, that's wonderful. I didn't know about that function and that is exactly what we need here. Thanks :-) Updated the PR.
|
@bnoordhuis Ping! |
lib/fs.js
Outdated
There was a problem hiding this comment.
Change in functionality. Here's an approximate test:
if (typeof path === 'number' && !Number.isInteger(path))
throw new TypeError('Not an integer');There was a problem hiding this comment.
or are you just short-circuiting for the fast path?
There was a problem hiding this comment.
This is a legacy functionality it seems. If we pass an fd to truncate it internally delegates it to ftruncate. So we cannot throw error here. We are just checking if it is a positive integer and move on to the next check if is not.
Are you suggesting to not to call ftruncate at all?
There was a problem hiding this comment.
I just followed the logic paths for current and this patch, and there seemed to be a discrepancy.
There was a problem hiding this comment.
@trevnorris Agree, but wouldn't this check be better?
There was a problem hiding this comment.
My assumption was to land most these changes on a minor, then making any breaking changes, that push this to semver-major, to another PR. If you're cool with this staying on major then I'll have another look from that perspective.
There was a problem hiding this comment.
@trevnorris I am okay with this being in major :-) Let's get this done right. Please suggest improvements as well :-)
|
Bump! |
There was a problem hiding this comment.
Change this and the below line to:
CHECK(args[1]->IsNumber());
const int64_t = args[1]->IntegerValue();Reason for the CHECK() is because we're now making an assumption about the incoming value. Always want to catch that if incorrect, because at this point if the value is incorrect then we've screwed up.
There was a problem hiding this comment.
wait. nm. read this as the fd value, not the len value.
EDIT: meaning, no need for the CHECK(). can still collapse the other.
|
to recap
|
|
ping @thefourtheye |
|
ping @thefourtheye ;) |
|
@targos Ah, I have this open for a loooong time. I'll get to it this week. Thanks for reminding :-) Last week @benjamingr also reminded me of this. |
000eee8 to
8233f9a
Compare
|
@trevnorris Sorry for the delay in getting your review comments addressed. PTAL. |
|
Added semver-major tag based on the discussion thread. Feel free to change that if it turns out not to be major after all. |
lib/fs.js
Outdated
There was a problem hiding this comment.
Change this to a TypeError. Also I'd replace "positive" with "unsigned".
6036668 to
3aab026
Compare
|
@trevnorris Changed positive to unsigned now. |
3aab026 to
f0b3208
Compare
|
Thanks for the change, and test. LGTM. |
7a953f9 to
f19c403
Compare
|
Rebased and improved the |
This patch moves the basic validation of arguments to `truncate` family of functions to the JavaScript from the C++ layer.
f19c403 to
693f14e
Compare
|
Rebased, after landing #7168. CI Run: https://ci.nodejs.org/job/node-test-pull-request/3378/ |
|
Landed in c86c1ee. |
This patch
1. moves the basic validation of arguments to `truncate` family
of functions to the JavaScript layer from the C++ layer.
2. makes sure that the File Descriptors are validated strictly.
PR-URL: #2498
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This reverts commit c86c1ee. original commit message: This patch 1. moves the basic validation of arguments to `truncate` family of functions to the JavaScript layer from the C++ layer. 2. makes sure that the File Descriptors are validated strictly. PR-URL: nodejs#2498 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This reverts commit c86c1ee. original commit message: This patch 1. moves the basic validation of arguments to `truncate` family of functions to the JavaScript layer from the C++ layer. 2. makes sure that the File Descriptors are validated strictly. PR-URL: nodejs#2498 Reviewed-By: Trevor Norris <trev.norris@gmail.com> PR-URL: nodejs#7950 Reviewed-By: Julien Gilli <jgilli@nodejs.org> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This patch moves the basic validation of arguments to
truncatefamilyof functions to the JavaScript from the C++ layer.
cc @bnoordhuis
CI Run: https://jenkins-iojs.nodesource.com/job/node-test-pull-request/131/