GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs.readSync & fs.read position argument does not support BigInt · Issue #36185 · nodejs/node

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

New issue
Copy link
New issue
Copy link
Closed
Closed
fs.readSync & fs.read position argument does not support BigInt#36185
Copy link
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.

Description

@mikeal
mikeal
opened on Nov 20, 2020
Issue body actions
  • Version: v14.10.1
  • Platform: Linux edef72861714 4.14.152-127.182.amzn2.x86_64 deps: update openssl to 1.0.1j #1 SMP Thu Nov 14 17:32:43 UTC 2019 x86_64 GNU/Linux

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.

Reacted by Alex Yang

Activity

Next
  1. mikeal
    changed the title [-]fs.readSync position argument does not support BigInt[/-] [+]fs.readSync & fs.read position argument does not support BigInt[/+] on Nov 20, 2020
  2. mikeal commented on Nov 20, 2020

    @mikeal
    mikeal
    on Nov 20, 2020
    ContributorAuthor
    More actions

    Also happens w/ fs.read

  3. benjamingr
    added
    feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
    on Nov 20, 2020
  4. benjamingr commented on Nov 20, 2020

    @benjamingr
    benjamingr
    on Nov 20, 2020
    Member
    More actions

    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:

    • 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 for the sync version.
    • Add a check if the typeof of the argument is a BigInt, if it is, coerce it to a Number and pass it to the same IsSafeInteger check.
    • Add a test to test-fs-read in test/parallel.
    • Update the docs in fs.md with a YAML comment indicating that fs.read and fs.readSync now potentially accept a BigInt (I think the actual docs don't need an update probably?)

    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.
    Reacted by Alex Yang
  5. benjamingr
    added
    good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
    on Nov 20, 2020
  6. BridgeAR commented on Nov 20, 2020

    @BridgeAR
    BridgeAR
    on Nov 20, 2020
    Member
    More actions

    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.

    Reacted by Momtchil Momtchev
  7. darvesh commented on Nov 20, 2020

    @darvesh
    darvesh
    on Nov 20, 2020
    More actions

    @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.

  8. mikeal commented on Nov 20, 2020

    @mikeal
    mikeal
    on Nov 20, 2020
    ContributorAuthor
    More actions

    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

    Reacted by Darvesh
  9. Trott
    removed
    good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
    on Nov 23, 2020
  10. Trott commented on Nov 23, 2020

    @Trott
    Trott
    on Nov 23, 2020
    Member
    More actions

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

    Reacted by Benjamin Gruenbaum
  11. jasnell commented on Nov 23, 2020

    @jasnell
    jasnell
    on Nov 23, 2020
    Member
    More actions

    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.

  12. kaizhu256 commented on Nov 23, 2020

    @kaizhu256
    kaizhu256
    on Nov 23, 2020
    Contributor
    More actions

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

  13. 2 remaining items

  14. aduh95
    added a commit that references this issue on Jan 13, 2021

    fs: allow `position` parameter to be a `BigInt` in read and readSync

    72b678a
  15. aduh95
    closed this as completedin 72b678aon Jan 13, 2021
  16. ruyadorno
    added a commit that references this issue on Jan 22, 2021

    fs: allow `position` parameter to be a `BigInt` in read and readSync

    c4cdf1d
  17. targos
    added a commit that references this issue on Aug 8, 2021

    fs: allow `position` parameter to be a `BigInt` in read and readSync

    f21f717
  18. BethGriggs
    added a commit that references this issue on Aug 12, 2021

    fs: allow `position` parameter to be a `BigInt` in read and readSync

    a45c38f
  19. MylesBorins
    added a commit that references this issue on Aug 31, 2021

    fs: allow `position` parameter to be a `BigInt` in read and readSync

    2459c11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.