From: "watson1978 (Shizuo Fujita) via ruby-core" Date: 2026-11-29T07:16:28+00:00 Subject: [ruby-core:127759] [Ruby Bug#22655] `eval("+1"*2**20)` dies with SIGILL instead of SystemStackError on Ruby 3.4/4.0 (Prism) Issue #22655 has been reported by watson1978 (Shizuo Fujita). ---------------------------------------- Bug #22655: `eval("+1"*2**20)` dies with SIGILL instead of SystemStackError on Ruby 3.4/4.0 (Prism) https://bugs.ruby-lang.org/issues/22655 * Author: watson1978 (Shizuo Fujita) * Status: Open * ruby -v: ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [arm64-darwin27] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ## Reproduction ``` $ ruby -e 'eval("+1"*2**20)' zsh: illegal hardware instruction ruby -e 'eval("+1"*2**20)' ``` It also happens without `eval`: ``` $ ruby -e 'File.write("plus.rb", "+1"*2**20)' $ ruby plus.rb zsh: illegal hardware instruction ruby plus.rb ``` The process is killed by SIGILL (exit status 132). Ruby prints nothing, not even a `[BUG]` report. ## Results macOS 27.3, arm64: | Ruby | Result | | --- | --- | | 3.3.12 | `stack level too deep (SystemStackError)` | | 3.4.10 +PRISM | crash (SIGILL) | | 3.4.10 `--parser=parse.y` | `stack level too deep (SystemStackError)` | | 4.0.7 +PRISM | crash (SIGILL) | | 4.0.7 `--parser=parse.y` | `stack level too deep (SystemStackError)` | | 4.1.0dev (2026-10-13 master c31e15064b) +PRISM | `stack level too deep (SystemStackError)` | With 4.0.7, the result depends on the size: | Input | Result | | --- | --- | | `"+1"*2**15` | OK | | `"+1"*2**16`, `"+1"*2**17` | `stack level too deep (SystemStackError)` | | `"+1"*2**18` and larger | crash (SIGILL) | I tested only on macOS. ## Analysis Parsing itself succeeds. `Prism.parse("+1"*2**20)` returns no errors, because the left-associative `+` chain does not count toward the nesting depth limit. The crash happens in two steps. 1. `pm_compile_node` and `pm_compile_call_node` recurse once for each `+`, and the machine stack overflows (about 58,000 frames). Ruby turns this overflow into `SystemStackError`. 2. While the exception propagates, `pm_parse_result_free` frees the AST with `pm_node_destroy`, which also recurses once for each `+`. With 2**18 or more levels, this overflows the machine stack again, and the second overflow kills the process. This is why 2**16 and 2**17 raise `SystemStackError` normally and 2**18 crashes. The stack at the SIGILL (lldb, 4.0.7, `eval` case): ``` * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGILL pm_node_destroy x174188 pm_node_list_destroy x1 pm_node_destroy x2 pm_parse_result_free x1 eval_make_iseq x1 eval_string_with_cref x1 rb_f_eval x1 vm_call_cfunc_with_frame_ x1 vm_exec_core x1 rb_vm_exec x1 rb_ec_exec_node x1 ruby_run_node x1 main x1 ``` 3.4.10 shows the same stack. In the file case, `pm_parse_result_free` is called from `ruby_process_options`. master does not crash, probably because 45250a4169 ("[PRISM] Use arena allocator for nodes") frees nodes without recursion. `ruby_4_0` (f388de2647) still frees nodes with `pm_node_destroy`. ## Related - [Bug #21114] (Prism hang on deeply nested `def`) - https://github.com/ruby/prism/issues/4305 (`PRISM_DEPTH_MAXIMUM` and the C stack size) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/