Skip to content

fs: validate position argument before length === 0 early return - #62674

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
geeksilva97:fix-fs-read-sync
Apr 14, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
geeksilva97:fix-fs-read-sync

Conversation

@geeksilva97

@geeksilva97 geeksilva97 commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Move position validation upwards to match documented behavior.

Fixes #62638

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Apr 10, 2026
@codecov

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

โœ… All modified and coverable lines are covered by tests.
โœ… Project coverage is 89.80%. Comparing base (68d7b6f) to head (de1c243).
โš ๏ธ Report is 546 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62674      +/-   ##
==========================================
+ Coverage   89.77%   89.80%   +0.03%     
==========================================
  Files         673      699      +26     
  Lines      203820   216235   +12415     
  Branches    39175    41331    +2156     
==========================================
+ Hits       182987   194199   +11212     
- Misses      13152    14148     +996     
- Partials     7681     7888     +207     
Files with missing lines Coverage ฮ”
lib/fs.js 98.19% <100.00%> (+<0.01%) โฌ†๏ธ
lib/internal/fs/promises.js 92.94% <100.00%> (-5.79%) โฌ‡๏ธ

... and 321 files with indirect coverage changes

๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • ๐Ÿ“ฆ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afurm

afurm commented Apr 11, 2026

Copy link
Copy Markdown

Moving validatePosition before the length === 0 early return is a good catch โ€” it means invalid positions are rejected even for zero-length reads, which is more consistent.

One question on the validation ordering: Previously, validateOffsetLengthRead ran before the position normalization, and validatePosition ran after. The relative ordering of validateOffsetLengthRead vs validatePosition changed โ€” do these validations have any ordering dependencies or could they produce different error messages depending on which runs first? For example, if position is valid but offset + length is out of bounds, which error should the user see first?

On the new test cases: The tests with empty buffer and an invalid position object are good โ€” but note that validatePosition will throw ERR_INVALID_ARG_TYPE for non-number objects. The existing tests in the same file use ERR_INVALID_ARG_TYPE for invalid positions, so this is consistent โ€” just making sure that is the intended behavior.

@avivkeller avivkeller added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Apr 12, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Apr 12, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@geeksilva97 geeksilva97 added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. commit-queue PRs queued for automated landing through the Commit Queue. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Apr 14, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Apr 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Apr 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/62674
โœ”  Done loading data for nodejs/node/pull/62674
----------------------------------- PR info ------------------------------------
Title      fs: validate position argument before length === 0 early return (#62674)
Author     Edy Silva <edigleyssonsilva@gmail.com> (@geeksilva97)
Branch     geeksilva97:fix-fs-read-sync -> nodejs:main
Labels     fs, author ready, needs-ci
Commits    1
 - fs: validate position argument before length === 0 early return
Committers 1
 - Edy Silva <edigleyssonsilva@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62674
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/62674
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
--------------------------------------------------------------------------------
   โ„น  This PR was created on Fri, 10 Apr 2026 16:46:18 GMT
   โœ”  Approvals: 2
   โœ”  - Aviv Keller (@avivkeller): https://github.com/nodejs/node/pull/62674#pullrequestreview-4094424429
   โœ”  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/62674#pullrequestreview-4101570935
   โœ”  Last GitHub CI successful
   โ„น  Last Full PR CI on 2026-04-14T09:32:37Z: https://ci.nodejs.org/job/node-test-pull-request/72680/
- Querying data for job/node-test-pull-request/72680/
โœ”  Build data downloaded
   โœ”  Last Jenkins CI successful
--------------------------------------------------------------------------------
   โœ”  No git cherry-pick in progress
   โœ”  No git am in progress
   โœ”  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
โœ”  origin/main is now up-to-date
- Downloading patch for 62674
From https://github.com/nodejs/node
 * branch                  refs/pull/62674/merge -> FETCH_HEAD
โœ”  Fetched commits as d0fa608c0796..de1c2438a977
--------------------------------------------------------------------------------
Auto-merging lib/fs.js
Auto-merging lib/internal/fs/promises.js
[main d32bcd2881] fs: validate position argument before length === 0 early return
 Author: Edy Silva <edigleyssonsilva@gmail.com>
 Date: Fri Apr 10 13:42:53 2026 -0300
 5 files changed, 84 insertions(+), 19 deletions(-)
   โœ”  Patches applied
--------------------------------------------------------------------------------
--------------------------------- New Message ----------------------------------
PR-URL: https://github.com/nodejs/node/pull/62674
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
--------------------------------------------------------------------------------
[main 908808fa7e] PR-URL: https://github.com/nodejs/node/pull/62674 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
 Author: Edy Silva <edigleyssonsilva@gmail.com>
 Date: Fri Apr 10 13:42:53 2026 -0300
 5 files changed, 84 insertions(+), 19 deletions(-)
  โœ–  908808fa7e8ca1d8b750911952a60a27d5d8302d
     โœ”  0:0      no Co-authored-by metadata                co-authored-by-is-trailer
     โœ”  0:0      skipping fixes-url                        fixes-url
     โœ–  1:0      blank line expected after title           line-after-title
     โœ”  0:0      line-lengths are valid                    line-length
     โœ”  0:0      metadata is at end of message             metadata-end
     โœ–  0:0      Commit must have a PR-URL.                pr-url
     โœ”  0:0      reviewers are valid                       reviewers
     โœ–  0:0      Invalid subsystem: "PR-URL"               subsystem
     โœ”  0:0      Title is formatted correctly.             title-format
     โœ”  0:0      Title is <= 50 columns.                   title-length
   โ„น  Please fix the commit message and try again.
Please manually ammend the commit message, by running
`git commit --amend`
Once commit message is fixed, finish the landing command running
`git node land --continue`
https://github.com/nodejs/node/actions/runs/24407872429