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

SIGSEGV on extremely nested ifs #6813

Closed
rijenkii opened this issue Jan 14, 2023 · 4 comments · Fixed by #6910
Closed

SIGSEGV on extremely nested ifs #6813

rijenkii opened this issue Jan 14, 2023 · 4 comments · Fixed by #6910
Assignees
Labels
Milestone

Comments

@rijenkii
Copy link

rijenkii commented Jan 14, 2023

Describe the bug

Inspired by denoland/deno#15117 and #5470.
When running swc on a file with 10000 nested ifs, it crashes with SIGSEGV.

To reproduce locally, use these commands:

python -c 'print("if (true) { " * 10000 + "console.log(true);" + " }" * 10000)' > test.js
npm i -D @swc/cli @swc/core
SWC_DEBUG=1 node node_modules/@swc/cli/bin/swc.js --sync test.js

Playground link

https://play.swc.rs/?version=1.3.26&code=H4sIAAAAAAAAA%2B3IsQmAMBRAwd4pfqmNCziORAkEA0YrcXcLSxewOF5zvLxEf%2BxnGuKKzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMwfz3VrtaSx1PV9U9ySJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSpD%2FUPSLuBdjzIgIA&config=H4sIAAAAAAAAA0WMTQrEIAxG75K1286id5hDBCctFv9IUhgR714tlu7C915ehUMsrBUyshCPS0pU%2FMMKZAOKZZcVTNf6tKEXagYUeScdiiyd%2BZSEJjUQXHRbGSWbQmYSeRHG3T9m66GQfucYKmjJdAc%2F0N7G%2FHPynaLySe0Cj9ke9LUAAAA%3D

Expected behavior

Either a correct output, or a sensible error.

Actual behavior

fish: Job 1, 'SWC_DEBUG=1 node node_modules/@…' terminated by signal SIGSEGV (Address boundary error)

Version

@swc/cli: 0.1.59, @swc/core: 1.3.26

@rijenkii rijenkii added the C-bug label Jan 14, 2023
@rijenkii
Copy link
Author

It seems that this example is also a reproduction for #5470, as swcx compile seems to throw an error similar to the one mentioned in denoland/deno#15117:

$ node node_modules/@swc/cli/bin/swcx.js compile test.js
Failed to determine swc core version from package.json, using latest available version 1.3.24 instead TypeError: Cannot read properties of undefined (reading '@swc/core')
    at getCoreVersion (/tmp/test/node_modules/@swc/cli/lib/swcx/index.js:62:52)
    at executeBinary (/tmp/test/node_modules/@swc/cli/lib/swcx/index.js:117:25)
    at Object.<anonymous> (/tmp/test/node_modules/@swc/cli/lib/swcx/index.js:134:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/tmp/test/node_modules/@swc/cli/bin/swcx.js:4:1)

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

@kdy1
Copy link
Member

kdy1 commented Jan 14, 2023

I don't think this can be fixed easily. To make error graceful, we have to handle allocation failure, but it's definitely not an easy task.

@kdy1 kdy1 removed this from the Not sure if it can be fixed milestone Jan 14, 2023
@rijenkii
Copy link
Author

Linked issues mentioned using rust-lang/stacker to avoid stack overflows, but as I understand integrating it would not be trivial.

@kdy1 kdy1 self-assigned this Feb 7, 2023
@kdy1 kdy1 added this to the Planned milestone Feb 7, 2023
@kdy1 kdy1 closed this as completed in #6910 Feb 7, 2023
kdy1 added a commit that referenced this issue Feb 7, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.33, v1.3.34 Feb 8, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 10, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants