Skip to content

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

Closed
@rubycon

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?

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues with confirmed bugs.errorsIssues and PRs related to JavaScript errors originated in Node.js core.fsIssues and PRs related to the fs subsystem / file system.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions