Uh oh!
There was an error while loading. Please reload this page.
fs: fix handling of struct stat fields - #8515
Conversation
There was a problem hiding this comment.
Escaping an empty handle isn't necessary. I realize this is copied from existing code, though.
There was a problem hiding this comment.
I’ll remove that in all locations here, then
bnoordhuis
commented
Sep 13, 2016
LGTM. Technically, it's |
`FChown` and `Chown` test that the `uid` and `gid` parameters they receive are unsigned integers, but `Stat()` and `FStat()` would return the corresponding fields of `uv_stat_t` as signed integers. Applications which pass those these values directly to `Chown` may fail (e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g. nodejs/node-v0.x-archive#5890). This patch changes the `Integer::New()` call for `uid` and `gid` to `Integer::NewFromUnsigned()`. All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either. Ref: npm/npm#13918
d309b1b to
28ccbf1Compareaddaleax
commented
Sep 13, 2016
Updated with |
bnoordhuis
commented
Sep 13, 2016
LGTM |
| // Integers. | ||
| #define X(name) \ | ||
| Local<Value> name = Integer::NewFromUnsigned(env->isolate(), s->st_##name); \ |
There was a problem hiding this comment.
This must be Integer::New, right?
addaleax
commented
Sep 13, 2016
@thefourtheye updated! :) |
thefourtheye
commented
Sep 13, 2016
I am not sure, if I am looking in the right place. But if I am following the definition here, correctly, even |
addaleax
commented
Sep 13, 2016
@thefourtheye Yeah, that doesn’t look like the right place… usually, you’d want to take a peek at the public headers which define That being said… yes, I’ve looked into it, and it seems the fields you mentioned are unsigned on Linux, too. Worse, |
bnoordhuis
commented
Sep 13, 2016
Pragmatically though, those are going to fit in a uint32_t for the foreseeable future (maybe, just maybe, with the exception of |
thefourtheye
commented
Sep 13, 2016
So, we are going to leave them as |
addaleax
commented
Sep 13, 2016
I’d be okay with that, if only for the fear of unnecessarily breaking things… alternatively, I can update this PR with something that auto-detects signedness of the fields? |
thefourtheye
commented
Sep 13, 2016
@addaleax Nah, we can keep it, simple, as it is. LGTM. I wonder how our CITGM never got this. |
addaleax
commented
Sep 13, 2016
I think one of the reasons is that it leaves quite a lot of code intact, it just blows up when you try to pass the uid/git to |
jasnell
left a comment
There was a problem hiding this comment.
LGTM but I wonder if there's a regression test that could be added for this.
addaleax
commented
Sep 15, 2016
@jasnell Maybe I could get a cctest for this together… I’ll look into that as soon as I have the time, but I kind of don’t want to block this PR on that because this PR itself would be a blocker for updating to |
addaleax
commented
Sep 18, 2016
addaleax
commented
Sep 19, 2016
Landed in c5545f2 |
`FChown` and `Chown` test that the `uid` and `gid` parameters they receive are unsigned integers, but `Stat()` and `FStat()` would return the corresponding fields of `uv_stat_t` as signed integers. Applications which pass those these values directly to `Chown` may fail (e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g. nodejs/node-v0.x-archive#5890). This patch changes the `Integer::New()` call for `uid` and `gid` to `Integer::NewFromUnsigned()`. All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either. Ref: npm/npm#13918 PR-URL: #8515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> undo accidental change to other fields of uv_fs_stat
At the time of writing, all currently published versions of Node.js return signed 32-bit integers in their return values for the `uid` and `gid` fields of `fs.Stats` instances. This is problematic, because some of Node’s other `fs` methods like `chown` expect unsigned 32-bit integer input and throw when encountering negative integers; this has broken e.g. `sudo npm install -g` on `OS X`, where `nobody` has a UID that would be returned as `-2` by `fs.stat()`. Ref: nodejs/node#8515 Ref: npm/npm#13918
`FChown` and `Chown` test that the `uid` and `gid` parameters they receive are unsigned integers, but `Stat()` and `FStat()` would return the corresponding fields of `uv_stat_t` as signed integers. Applications which pass those these values directly to `Chown` may fail (e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g. nodejs/node-v0.x-archive#5890). This patch changes the `Integer::New()` call for `uid` and `gid` to `Integer::NewFromUnsigned()`. All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either. Ref: npm/npm#13918 PR-URL: #8515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> undo accidental change to other fields of uv_fs_stat
MylesBorins
commented
Oct 24, 2016
@addaleax should this be backported? |
addaleax
commented
Oct 24, 2016
@thealphanerd This seems to land cleanly on v4.x-staging with tests passing, and it makes sense to have this on LTS for me. |
`FChown` and `Chown` test that the `uid` and `gid` parameters they receive are unsigned integers, but `Stat()` and `FStat()` would return the corresponding fields of `uv_stat_t` as signed integers. Applications which pass those these values directly to `Chown` may fail (e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g. nodejs/node-v0.x-archive#5890). This patch changes the `Integer::New()` call for `uid` and `gid` to `Integer::NewFromUnsigned()`. All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either. Ref: npm/npm#13918 PR-URL: #8515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> undo accidental change to other fields of uv_fs_stat
`FChown` and `Chown` test that the `uid` and `gid` parameters they receive are unsigned integers, but `Stat()` and `FStat()` would return the corresponding fields of `uv_stat_t` as signed integers. Applications which pass those these values directly to `Chown` may fail (e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g. nodejs/node-v0.x-archive#5890). This patch changes the `Integer::New()` call for `uid` and `gid` to `Integer::NewFromUnsigned()`. All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either. Ref: npm/npm#13918 PR-URL: #8515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> undo accidental change to other fields of uv_fs_stat
Checklist
make -j4 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
fs
Description of change
FChownandChowntest that theuidandgidparameters they receive are unsigned integers, butStat()andFStat()would return the corresponding fields ofstruct statas signed integers. Applications which pass those these values directly toChownmay fail(e.g. for
nobodyon OS X, who has anuidof-2, see e.g. nodejs/node-v0.x-archive#5890).This patch changes the
Integer::New()call foruidandgidtoInteger::NewFromUnsigned().All other fields are kept as they are, for performance, but strictly speaking the respective sizes of those fields aren’t specified, either.
Ref: npm/npm#13918
/cc @nodejs/fs
CI: https://ci.nodejs.org/job/node-test-commit/5026/