-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Race condition on array length checks #47928
Comments
Can you reproduce it with node v20.x or the main branch? |
Platform: Node version: Core dump message below. Able to reproduce.
|
same result with --max-old-space-size=4096 and 8192. |
I can reproduce the issue. @alex-h-strachan what makes you think this is due to a race condition, i.e., concurrent operations? |
I took a look. It's an unfortunate issue of error behavior divergence due to optimized code. tl;dr This is https://bugs.chromium.org/p/chromium/issues/detail?id=1201626, in particular this TODO In the first snippet, In the second snippet, I'll cc in compiler folks in chromium:1201626. |
@syg thanks for the detective work there. |
$ node -e "const x = []; for(i = 0; i < 112813859; i++){ x[i] = false };"
[eval]:1
const x = []; for(i = 0; i < 112813859; i++){ x[i] = false };
^
RangeError: Invalid array length
at [eval]:1:52
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:118:14
at [eval]-wrapper:6:24
at runScript (node:internal/process/execution:101:62)
at evalScript (node:internal/process/execution:136:3)
at node:internal/main/eval_string:55:3
Node.js v22.6.0 This appears to no longer cause a core dump. I've optimistically closed this issue, but feel free to reopen if you disagree. |
I encountered this issue on v20.
|
I haven't confirmed the reproduction, but I've reopened this issue with the appropriate labels. |
Confirmed reproduction on Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 x86_64 running Node v20.16.0 |
Version
v18.16.0
Platform
Darwin Alexs-MacBook-Pro-2.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
node -e "const x = []; for(i = 0; i < 112813859; i++){ x[i] = false };"
will result in a core dump
however:
node -e "const x = []; for(i = 0; i < 112813858; i++){ x[i] = false }; for(i = 0; i < 112813859; i++){ x[i] = false };"
correctly produces
RangeError: Invalid array length
It seems initializing a large but legal array causes the checker to prime itself and guard against the next, illegal call.
Core dump log from the first command:
How often does it reproduce? Is there a required condition?
100% reproducible, even adjusting
--max_old_space_size
What is the expected behavior? Why is that the expected behavior?
I expect the userland
RangeError: Invalid array length
to be raised any time an illegal array is constructed rather than a core dump.I certainly don't expect a different behavior depending on if an almost-too-large array was constructed immediately before.
What do you see instead?
Core dump process explosion rather than an error.
Additional information
No response
The text was updated successfully, but these errors were encountered: