-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Too many nested for-loops causes segfault #817
Comments
Does it happen if you run the file with That would answer if the bug is in the transpiler or if the bug is in how Bun embeds JavaScriptCore |
Yes; It may be worth testing this on the Safari browser, to see if JavaScriptCore actually has protection for this kind of call stack issue. |
Just tested it on my roommate's MacBook, in Safari's built in JS console. It manages to handle way more nested |
In bun version 1.0, it's now able to survive a shocking 8,710 nested loops when running, but the behavior is still quite strange. I once again have an original let counter = 0;
for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++)
for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++)
for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++)
(... copied and pasted many, many times)
for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) for (let i = 0; i < 1; i++) counter++;
console.log(counter); When there are precisely 8,711 instances of I also tested the number of |
This is the segfault I get when trying to reproduce the above snippet with ~2500 lines.
It looks like a stackoverflow (?) And this is what the main thread is doing:
|
This is a stack overflow in Bun's JS parser |
Version
0.1.4
Platform
Linux jbook 5.18.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.5-1 (2022-06-16) x86_64 GNU/Linux
What steps will reproduce the bug?
Create a JS file with a LOT of nested
for
loops - specifically 1,875 of them on my system.Attempt to run the file with Bun:
it crashes with a segfault instead of throwing a JS RangeError.
How often does it reproduce? Is there a required condition?
It reproduces reliably once you add enough
for
loops.What is the expected behavior?
Expected: Something akin to this, as Bun already can throw RangeErrors for recursive functions:
This is what NodeJS throws:
It's worth noting that Node throws a RangeError after "only" 1,274 nested loops (on my system).
What do you see instead?
Additional information
This is minor, since it's an edge case, but still worth reporting I'm sure, to improve Bun's stability.
The text was updated successfully, but these errors were encountered: