Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: throws error if position argument is bigint in fs.readSync & fs.read #36198

Closed
wants to merge 6 commits into from

Conversation

darvesh
Copy link

@darvesh darvesh commented Nov 20, 2020

Fixes #36185

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • test included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Nov 20, 2020
@jasnell
Copy link
Member

jasnell commented Nov 22, 2020

hmm... while the changes in this look good, I'm actually wondering if we shouldn't go the other way and actually allow bigints in these apis.

@darvesh
Copy link
Author

darvesh commented Nov 22, 2020

hmm... while the changes in this look good, I'm actually wondering if we shouldn't go the other way and actually allow bigints in these apis.

As @BridgeAR mentioned here, isn't it better to let the user handle it on their own?
Also though it might be misleading since people may assume fs.read will work with offsets larger than integers which it doesn't.

@@ -543,6 +543,9 @@ function read(fd, buffer, offset, length, position, callback) {

validateOffsetLengthRead(offset, length, buffer.byteLength);

if (typeof position === 'bigint')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a check that can be performed early instead of being this late? Before validateBuffer would be a good place I think.

Copy link
Author

@darvesh darvesh Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have arguments validation in order?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern was mostly about the if (length === 0) above which means if the length is 0 you'd be able to get away with these checks..but thinking again it was already the case for a few other cases above, so it's probably not a bit deal.

@darvesh
Copy link
Author

darvesh commented Dec 7, 2020

I think this can be closed in favour of #36190

@aduh95 aduh95 closed this Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.readSync & fs.read position argument does not support BigInt
5 participants