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.readSync & fs.read position argument does not support BigInt #36185

Closed
mikeal opened this issue Nov 20, 2020 · 9 comments
Closed

fs.readSync & fs.read position argument does not support BigInt #36185

mikeal opened this issue Nov 20, 2020 · 9 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@mikeal
Copy link
Contributor

mikeal commented Nov 20, 2020

What steps will reproduce the bug?

readSync(reader, buffer, 0, 12, BigInt(position))           

How often does it reproduce? Is there a required condition?

Everytime.

What is the expected behavior?

It should read from the position in the file, and it will if you use Number(position) on a BigInt position.

What do you see instead?

The call reads data into the buffer but it begins at position 0 in the file instead of at the position noted in the BigInt.

@mikeal mikeal changed the title fs.readSync position argument does not support BigInt fs.readSync & fs.read position argument does not support BigInt Nov 20, 2020
@mikeal
Copy link
Contributor Author

mikeal commented Nov 20, 2020

Also happens w/ fs.read

@benjamingr benjamingr added the feature request Issues that request new features to be added to Node.js. label Nov 20, 2020
@benjamingr
Copy link
Member

This is the same behaviour fs.read and fs.readSync have with anything that is not a Number or fails Number.isSafeInteger.

I think this is a reasonable improvement. Though it might be misleading since people may assume fs.read will work with offsets larger than integers which it doesn't.

I think a fix would be to:

A more elaborate fix would be to try and get reads to work with position > Int32, which would require:

  • Going to node_file.cc static void Read(const FunctionCallbackInfo<Value>& args)
  • Remove the IsSafeJsInt check in line 2039
  • Instead of reading the value as Integer in line 2040, check IsBigInt() and if so read it as a BigInt (an int64 is probably still fine for most cases since a 64 bit offset into a file is 9,223,372,036,854,775,807 bytes big which is still quite theoretical I believe).
  • uv_fs_read is already being passed a 64 bit integer so the actual offset itself should work.

@benjamingr benjamingr added the good first issue Issues that are suitable for first-time contributors. label Nov 20, 2020
@BridgeAR
Copy link
Member

Instead of coercing the value to a number, I'd in fact throw an error. That way there's just a single way to do this and the immediate feedback should be fine to let the user handle the coercing on their own or to use a number instead.

@darvesh
Copy link

darvesh commented Nov 20, 2020

@BridgeAR Shall I work on this?
If I'm right I have to go here: https://github.com/nodejs/node/blob/master/lib/fs.js#L546-L547 and https://github.com/nodejs/node/blob/master/lib/fs.js#L598-L599 and throw error if typeof position === "bigint" then add a test to test-fs-read in test/parallel.

@mikeal
Copy link
Contributor Author

mikeal commented Nov 20, 2020

Though it might be misleading since people may assume fs.read will work with offsets larger than integers which it doesn't.

Why you gotta go and make my max file size 9 petabytes! 😭 This is so unreasonable 🤬

j/k

@Trott Trott removed the good first issue Issues that are suitable for first-time contributors. label Nov 23, 2020
@Trott
Copy link
Member

Trott commented Nov 23, 2020

(Removed good first issue because there are at least two open PRs that address this.)

@jasnell
Copy link
Member

jasnell commented Nov 23, 2020

Given that it is perfectly fine to have bigints well within the acceptable range, I'd say that accepting a BigInt should be fine. We can throw a RangeError if too large of a bigint is provided.

@kaizhu256
Copy link
Contributor

if bigint is allowed, would bigdecimal also be allowed if it hypothetically reaches stage 4?

@benjamingr
Copy link
Member

if bigint is allowed, would bigdecimal also be allowed if it hypothetically reaches stage 4?

BigDecimal is currently stage 1, very early in the stage process. I say one bridge at a time.

@aduh95 aduh95 closed this as completed in 72b678a Jan 13, 2021
ruyadorno pushed a commit that referenced this issue Jan 22, 2021
Fixes: #36185

PR-URL: #36190
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos pushed a commit that referenced this issue Aug 8, 2021
Fixes: #36185

PR-URL: #36190
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Aug 12, 2021
Fixes: #36185

PR-URL: #36190
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
MylesBorins pushed a commit that referenced this issue Aug 31, 2021
Fixes: #36185

PR-URL: #36190
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
foxxyz pushed a commit to foxxyz/node that referenced this issue Oct 18, 2021
Fixes: nodejs#36185

PR-URL: nodejs#36190
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
7 participants