node icon indicating copy to clipboard operation
node copied to clipboard

fs: fix TypeError in glob when directory access is denied

Open Sylphy-0xd3ac opened this issue 7 months ago β€’ 5 comments

When a directory cannot be read due to permission issues, the async version of fs.glob() returns null from readdir(), while the sync version returns an empty array. This causes a TypeError when trying to access the 'length' property of null.

Fix by making the async readdir() method return an empty array on error, consistent with the sync version behavior.

Fixes: https://github.com/nodejs/node/issues/58670 Fixes: https://github.com/nodejs/node/issues/58276

Sylphy-0xd3ac avatar Jun 11 '25 11:06 Sylphy-0xd3ac

This is nice! Thanks! Would you mind adding a test case? Just make sure that it will never return null

juanarbol avatar Jun 11 '25 19:06 juanarbol

@juanarbol Done. Added test case

Sylphy-0xd3ac avatar Jun 12 '25 13:06 Sylphy-0xd3ac

CI: https://ci.nodejs.org/job/node-test-pull-request/67430/

nodejs-github-bot avatar Jun 13 '25 17:06 nodejs-github-bot

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.99%. Comparing base (5ebfb99) to head (59b82bb). :warning: Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58674      +/-   ##
==========================================
+ Coverage   89.97%   89.99%   +0.02%     
==========================================
  Files         649      649              
  Lines      192194   192194              
  Branches    37678    37683       +5     
==========================================
+ Hits       172918   172958      +40     
+ Misses      11873    11836      -37     
+ Partials     7403     7400       -3     
Files with missing lines Coverage Ξ”
lib/internal/fs/glob.js 91.98% <100.00%> (ΓΈ)

... and 40 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 13 '25 17:06 codecov[bot]

Delete the test-fs-glob-readdir-error-handling.mjs file as its functionality is now covered by the test-fs-glob.mjs

Sylphy-0xd3ac avatar Jun 15 '25 23:06 Sylphy-0xd3ac

CI: https://ci.nodejs.org/job/node-test-pull-request/67483/

nodejs-github-bot avatar Jun 16 '25 14:06 nodejs-github-bot

Add PR-URL and Reviewed-By fields to the commit message

Sylphy-0xd3ac avatar Jun 24 '25 12:06 Sylphy-0xd3ac

I think you need to stop force-pushing so it can land. Another contributor can correct me if I'm wrong though

Ethan-Arrowood avatar Jun 26 '25 15:06 Ethan-Arrowood

Sorry for the force-push. Could you please help re-approve this PR so it can land? Thank you

Sylphy-0xd3ac avatar Jun 27 '25 08:06 Sylphy-0xd3ac

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - fs: fix glob TypeError on restricted dirs
   ⚠  - Merge branch 'nodejs:main' into main
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/16320742288

github-actions[bot] avatar Jul 16 '25 13:07 github-actions[bot]

It seems like the CI did not run because new commits were pushed after the last approving review?

Sylphy-0xd3ac avatar Jul 17 '25 07:07 Sylphy-0xd3ac

CI: https://ci.nodejs.org/job/node-test-pull-request/67988/

nodejs-github-bot avatar Jul 17 '25 20:07 nodejs-github-bot

The last CI failures ultimately point to node-test-commit-arm-debug node-test-binary-windows-js-suites The first one had network issues when cloning the git repository, the second one had ECONNRESET error during inspector testing. This might be coincidental since there have never been problems before. PR #59091 explains the why Windows CI failure in this PR.

Sylphy-0xd3ac avatar Jul 19 '25 00:07 Sylphy-0xd3ac

CI: https://ci.nodejs.org/job/node-test-pull-request/68050/

nodejs-github-bot avatar Jul 21 '25 07:07 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/68052/

nodejs-github-bot avatar Jul 21 '25 09:07 nodejs-github-bot

Another CI node-test-commit-aix failure: ENOSPC: System limit for number of file watchers reached Looks like a coincidental issue again

Sylphy-0xd3ac avatar Jul 22 '25 14:07 Sylphy-0xd3ac

@Sylphy-0xd3ac It seems your first commit doesn't have the correct author. Can you squash all your 10 commits and make sure to --reset-author?

RafaelGSS avatar Jul 31 '25 21:07 RafaelGSS

@RafaelGSS I did it, is that it?

Sylphy-0xd3ac avatar Aug 01 '25 00:08 Sylphy-0xd3ac

@RafaelGSS I did it, is that it?

Yes! Once CI is green (again), PR will be merged.

RafaelGSS avatar Aug 01 '25 12:08 RafaelGSS

CI: https://ci.nodejs.org/job/node-test-pull-request/68349/ πŸ’›

nodejs-github-bot avatar Aug 01 '25 13:08 nodejs-github-bot

Landed in 5794e644

jasnell avatar Aug 01 '25 14:08 jasnell