Skip to content

fs: too strict range check on 'mode' parameter #20498

Description

@rubycon
  • Version: 10.0.0
  • Platform: MacOS 10.12.6 (Sierra)
  • Subsystem: fs

Since version 10, function like fs.chmod() or fs.mkdir() check if their mode parameter is below o777 throwing a RangeError exception if the condition isn't satisfied.
This requirement is too strict as the mode parameter can often be above o777 if it need to set the S_ISUID or S_ISGID bits.

Furthermore this range check break several node packages (e.g. graceful-fs used by over 1400 other packages) in a very common scenario:
A program wants to create a new file/directory with the same rights that a reference file/directory. Often the mode attribute of fs.Stats object is directly passed to fs.chmod() or fs.mkdir(). However the fs.Stats.mode is always above o777 (e.g. o100644) since it also contains the file type bits.

Classic POSIX version of chmod or mkdir seems to handle those kind a values without complaining by discarding the irrelevant bits instead of throwing an error. Why do Node need to be so brutal about it?

Activity

  1. arantes555 commented on May 3, 2018

    @arantes555

    Seeing the same issue here. Breaking graceful-fs actually breaks vinyl-fs, so it actually breaks gulp (yes, even gulp@4).

    In my case, I only see the issue when running on CI...

  2. joyeecheung commented on May 4, 2018

    @joyeecheung
    Member

    cc @targos @BridgeAR We discussed about unifying this check in #19973 (review) I am leaning towards masking off the relevant bits since that's what the underlying POSIX API usually does.

  3. added
    fsIssues and PRs related to file-system APIs and the fs module.
    errorsIssues and PRs related to JavaScript errors originating in Node.js core.
    on May 4, 2018
  4. joyeecheung commented on May 4, 2018

    @joyeecheung
    Member

    Also cc @jasnell the check is added in #17334

  5. self-assigned this
    on May 4, 2018
  6. jasnell commented on May 4, 2018

    @jasnell
    Member

    I'm good with masking off the bits and relaxing the check :)

  7. jasnell commented on May 4, 2018

    @jasnell
    Member

    Also, it's obvious we don't have good test coverage for this particular case so it would be good to expand that a bit.

  8. BridgeAR commented on May 4, 2018

    @BridgeAR
    Member

    I also agree that masking off seems the right thing to do.

  9. demurgos commented on May 6, 2018

    @demurgos
    Contributor

    Hi,
    I just wanted to mention that I also encountered this bug. It happens when I use Gulp (graceful-fs) on Gitlab CI:

    RangeError [ERR_OUT_OF_RANGE]: The value of "mode" is out of range. Received 33206
        at Object.fs.fchmod (fs.js:1024:11)
        at Object.fchmod (/builds/demurgos/node-devkit/node_modules/graceful-fs/polyfills.js:237:17)
        at mode (/builds/demurgos/node-devkit/node_modules/vinyl-fs/lib/file-operations.js:237:10)
        at onStat (/builds/demurgos/node-devkit/node_modules/vinyl-fs/lib/file-operations.js:227:14)
        at /builds/demurgos/node-devkit/node_modules/graceful-fs/polyfills.js:287:18
        at FSReqWrap.oncomplete (fs.js:150:5)
    
  10. alanonthegit commented on May 7, 2018

    @alanonthegit

    I'm having the same issue above with Gulp 4(graceful-fs) in my local build. What can I do to fix this?

  11. seeker5084 commented on May 8, 2018

    @seeker5084

    same here.

  12. seeker5084 commented on May 10, 2018

    @seeker5084

    graceful-fs's RangeError [ERR_OUT_OF_RANGE] solved by #20588.
    Great work. Thanks!

  13. 52 remaining items

  14. delagen commented on Jun 14, 2018

    @delagen

    When it will be in master? 10.4.1 released but still
    RangeError [ERR_OUT_OF_RANGE]: The value of "mode" is out of range. Received 33206
    at Object.fs.fchmod (fs.js:1058:11)

  15. joyeecheung commented on Jun 14, 2018

    @joyeecheung
    Member

    @delagen It's on v10.x-staging now, should be available in the next release.

  16. delagen commented on Jun 14, 2018

    @delagen

    @joyeecheung This was broken for about 7 releases of 10.x branch. Speed of fixes make me sad (

  17. bnoordhuis commented on Jun 14, 2018

    @bnoordhuis
    Member

    Comments like yours make me sad. It adds nothing except another notification email to 100+ people.

  18. added a commit that references this issue on Jun 20, 2018
  19. added a commit that references this issue on Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues and PRs for confirmed bugs.errorsIssues and PRs related to JavaScript errors originating in Node.js core.fsIssues and PRs related to file-system APIs and the fs module.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions