Skip to content

fs: fix TypeError in glob when directory access is denied #58674

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

Closed
wants to merge 1 commit into from

Conversation

Sylphy-0xd3ac
Copy link
Contributor

@Sylphy-0xd3ac Sylphy-0xd3ac commented Jun 11, 2025

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: #58670
Fixes: #58276

@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 Jun 11, 2025
@juanarbol
Copy link
Member

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

@Sylphy-0xd3ac
Copy link
Contributor Author

Sylphy-0xd3ac commented Jun 12, 2025

@juanarbol Done. Added test case

Copy link
Member

@juanarbol juanarbol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@juanarbol juanarbol added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.99%. Comparing base (5ebfb99) to head (59b82bb).
⚠️ 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

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

@Sylphy-0xd3ac Sylphy-0xd3ac force-pushed the main branch 2 times, most recently from 6b33002 to 7ae4597 Compare June 14, 2025 08:44
@Sylphy-0xd3ac
Copy link
Contributor Author

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

@Ethan-Arrowood Ethan-Arrowood added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 16, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 16, 2025
@nodejs-github-bot
Copy link
Collaborator

@Sylphy-0xd3ac Sylphy-0xd3ac force-pushed the main branch 3 times, most recently from 8c18cc5 to 0a4f0f9 Compare June 24, 2025 10:55
@Sylphy-0xd3ac
Copy link
Contributor Author

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

@Sylphy-0xd3ac Sylphy-0xd3ac force-pushed the main branch 3 times, most recently from f1789b7 to a5fdb0f Compare June 25, 2025 23:48
@Ethan-Arrowood
Copy link
Contributor

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

@Sylphy-0xd3ac
Copy link
Contributor Author

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

Copy link
Contributor

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

@Sylphy-0xd3ac
Copy link
Contributor Author

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

@Ethan-Arrowood Ethan-Arrowood added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Jul 17, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 17, 2025
@nodejs-github-bot
Copy link
Collaborator

@Sylphy-0xd3ac
Copy link
Contributor Author

Sylphy-0xd3ac commented Jul 19, 2025

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.

@StefanStojanovic StefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 21, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@Sylphy-0xd3ac
Copy link
Contributor Author

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

@RafaelGSS RafaelGSS added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 31, 2025
@RafaelGSS
Copy link
Member

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

Verified

This commit was signed with the committer’s verified signature.
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.

PR-URL: #58674
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan-Arrowood <ethan@arrowood.dev>
Reviewed-By: Juan José <soyjuanarbol@gmail.com>
@Sylphy-0xd3ac
Copy link
Contributor Author

@RafaelGSS I did it, is that it?

@RafaelGSS
Copy link
Member

@RafaelGSS I did it, is that it?

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

@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 1, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 1, 2025
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Aug 1, 2025

jasnell pushed a commit that referenced this pull request Aug 1, 2025
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.

PR-URL: #58674
Fixes: #58670
Fixes: #58276
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan-Arrowood <ethan@arrowood.dev>
Reviewed-By: Juan José <soyjuanarbol@gmail.com>
@jasnell
Copy link
Member

jasnell commented Aug 1, 2025

Landed in 5794e64

@jasnell jasnell closed this Aug 1, 2025
meteorqz6 pushed a commit to meteorqz6/node that referenced this pull request Aug 2, 2025
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.

PR-URL: nodejs#58674
Fixes: nodejs#58670
Fixes: nodejs#58276
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan-Arrowood <ethan@arrowood.dev>
Reviewed-By: Juan José <soyjuanarbol@gmail.com>
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
7 participants