Skip to content
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

Fixed an issue that caused a segmentation fault when resolving a module in certain environments #56657

Closed
wants to merge 2 commits into from

Conversation

yamachu
Copy link
Contributor

@yamachu yamachu commented Jan 19, 2025

Fix: #56650

This PR fixes a problem that caused a segmentation fault in module resolution when creating a require object with multibyte characters in a non-English environment.

Since the issue occurred when generating a std::filesystem::path object, some patches were applied to the changed areas in the following PR.

a7dad43

Caution

It cannot be reproduced by using chcp command in a Windows environment, and it is necessary to change the locale in the OS settings...

Enforce that it is u8 because it was crashing
when loading files containing Japanese in Windows, cp392 environment.

Fixes: nodejs#56650
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jan 19, 2025
Copy link
Member

@lpinca lpinca left a comment

Choose a reason for hiding this comment

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

RSLGTM

@lpinca
Copy link
Member

lpinca commented Jan 19, 2025

It cannot be reproduced by using chcp command in a Windows environment, and it is necessary to change the locale in the OS settings...

I guess there is no easy way to add a test, right?

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.21%. Comparing base (009d53e) to head (bc1a91e).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
src/node_modules.cc 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56657      +/-   ##
==========================================
- Coverage   89.21%   89.21%   -0.01%     
==========================================
  Files         662      662              
  Lines      191893   191895       +2     
  Branches    36931    36928       -3     
==========================================
- Hits       171196   171191       -5     
- Misses      13541    13546       +5     
- Partials     7156     7158       +2     
Files with missing lines Coverage Δ
src/node_modules.cc 78.91% <83.33%> (-0.19%) ⬇️

... and 17 files with indirect coverage changes

@yamachu
Copy link
Contributor Author

yamachu commented Jan 20, 2025

Yes.
Maybe I'm just not familiar with Windows commands, but I think the only way is through GUI operation.
This makes it very difficult to run test.

@yamachu
Copy link
Contributor Author

yamachu commented Jan 20, 2025

I have succeeded in reproducing the Japanese environment Windows on CI.
I also ran it on default Windows and Japanese environment Windows and confirmed that only the Japanese environment failed.

https://github.com/yamachu/node-require-japanese-repro/actions/runs/12861537170

To prepare a test using this setup in the node repository, I also need a node build workflow for Windows, which is difficult for me...

@lpinca
Copy link
Member

lpinca commented Jan 20, 2025

Can you please fix the linting errors?

@yamachu
Copy link
Contributor Author

yamachu commented Jan 20, 2025

@lpinca I ran make test but forgot to run make lint, sorry.
I pushed the formatted file again.

@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 20, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 21, 2025
@nodejs-github-bot

This comment was marked as outdated.

@yamachu
Copy link
Contributor Author

yamachu commented Jan 22, 2025

Thank you for the review.
I noticed that the test regarding unicode was failing in the CI for coverage-windows, so I fixed it in another PR.
Therefore, I will close this PR and take a different approach.

Since I was able to create a ja-JP environment with CI, I performed tests using it.
The summary of the test is as follows.

Default Windows runner
Before https://github.com/yamachu/node/actions/runs/12890202110/job/35939236599#step:7:17013
After https://github.com/yamachu/node/actions/runs/12890008746/job/35938588016#step:7:17010

  Failed tests:
  D:\a\node\node\out\Release\node.exe --experimental-vm-modules --max-old-space-size=16 --trace-gc D:\a\node\node\test\es-module\test-vm-source-text-module-leak.js
  D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-child-process-exec-any-shells-windows.js
  D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-inspector-wait-for-connection.js
+ D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-require-unicode.js
  D:\a\node\node\out\Release\node.exe --expose-internals D:\a\node\node\test\pummel\test-heapdump-inspector.js

SJIS Windows runner
Before https://github.com/yamachu/node/actions/runs/12890202110/job/35939236599#step:12:16851
After https://github.com/yamachu/node/actions/runs/12890008746/job/35938588016#step:12:16853

  Failed tests:
  D:\a\node\node\out\Release\node.exe --experimental-vm-modules --max-old-space-size=16 --trace-gc D:\a\node\node\test\es-module\test-vm-source-text-module-leak.js
  D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-child-process-exec-any-shells-windows.js
- D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-module-create-require-multibyte.js
  D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-require-unicode.js
  D:\a\node\node\out\Release\node.exe D:\a\node\node\test\parallel\test-inspector-wait-for-connection.js
  D:\a\node\node\out\Release\node.exe --expose-internals D:\a\node\node\test\pummel\test-heapdump-inspector.js

@nodejs-github-bot
Copy link
Collaborator

@lpinca
Copy link
Member

lpinca commented Jan 23, 2025

@yamachu is this superseded by #56696?

@yamachu
Copy link
Contributor Author

yamachu commented Jan 23, 2025

@lpinca Yes.
I have found that this approach did not solve this issue and I'm fixing it in #56696.

I will close this PR for that purpose.
Thank you for your review.

@yamachu yamachu closed this Jan 23, 2025
lpinca pushed a commit that referenced this pull request Jan 25, 2025
PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
lpinca pushed a commit that referenced this pull request Jan 25, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@yamachu yamachu deleted the resolve-path-by-using-u8string branch January 25, 2025 16:08
aduh95 pushed a commit that referenced this pull request Jan 27, 2025
PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jan 27, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
sevenc-nanashi pushed a commit to sevenc-nanashi/node that referenced this pull request Jan 29, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: nodejs#56696
Fixes: nodejs#56650
Refs: nodejs#56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
sevenc-nanashi pushed a commit to sevenc-nanashi/node that referenced this pull request Jan 29, 2025
PR-URL: nodejs#56696
Fixes: nodejs#56650
Refs: nodejs#56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jan 30, 2025
PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jan 30, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
hvanness pushed a commit to hvanness/node that referenced this pull request Jan 30, 2025
PR-URL: nodejs#56696
Fixes: nodejs#56650
Refs: nodejs#56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
hvanness pushed a commit to hvanness/node that referenced this pull request Jan 30, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: nodejs#56696
Fixes: nodejs#56650
Refs: nodejs#56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jan 31, 2025
PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jan 31, 2025
Take a similar approach to node_file and allow the creation of paths
code point must be specified to convert from wchar_t to utf8.

PR-URL: #56696
Fixes: #56650
Refs: #56657
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation Fault When Passing Paths with Japanese Characters to createRequire in Node.js 22+
5 participants