Skip to content

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

Open
geeksilva97 wants to merge 1 commit intonodejs:mainfrom
geeksilva97:fix-fs-read-sync
Open

fs: validate position argument before length === 0 early return#62674
geeksilva97 wants to merge 1 commit intonodejs:mainfrom
geeksilva97:fix-fs-read-sync

Conversation

@geeksilva97
Copy link
Copy Markdown
Contributor

@geeksilva97 geeksilva97 commented Apr 10, 2026

Move position validation upwards to match documented behavior.

Fixes #62638

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

codecov bot commented Apr 10, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 89.80%. Comparing base (68d7b6f) to head (de1c243).
⚠️ Report is 517 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
Copy link
Copy Markdown

afurm commented Apr 11, 2026

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.

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. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.readSync does not validate invalid position type (accepts object instead of throwing)

3 participants