Project

General

Profile

Actions

Bug #22560

open

parse.y hits UNREACHABLE_RETURN(0) after compile_error in rb_parser_enc_cr_str_buf_cat

Bug #22560: parse.y hits UNREACHABLE_RETURN(0) after compile_error in rb_parser_enc_cr_str_buf_cat

Added by steviejj (Steven Johnstone) about 12 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27]
[ruby-core:127559]

Description

In CRuby's parse.y, rb_parser_enc_cr_str_buf_cat calls non-fatal compile_error(p, "incompatible character encodings: ...") (parser_compile_error / ripper_compile_error) followed immediately by UNREACHABLE_RETURN(0) (__builtin_unreachable()). Because compile_error appends the syntax error and returns normally rather than longjmping, control flow falls off __builtin_unreachable() into undefined code.

This is reliably triggered by tokadd_utf8 / tokadd_codepoint passing a hardcoded rb_utf8_encoding() instead of p->enc to flush_string_content on an invalid or unterminated \u{...} escape inside an ASCII-8BIT string literal spanning a newline (p->delayed.token).

ruby -e 'STDOUT.binmode; STDOUT.write("#coding:ascii-8bit\n\"\x80\n\x80\\u{0")' > foo.rb

✗ lldb ruby
(lldb) target create "ruby"
Current executable set to '/opt/homebrew/opt/ruby/bin/ruby' (arm64).
(lldb) run --parser=parse.y foo.rb
Process 19325 launched: '/opt/homebrew/opt/ruby/bin/ruby' (arm64)
warning: (arm64) /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/enc/encdb.bundle empty dSYM file detected, dSYM was created with an executable with no debug info.
warning: (arm64) /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/enc/trans/transdb.bundle empty dSYM file detected, dSYM was created with an executable with no debug info.
warning: (arm64) /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/monitor.bundle empty dSYM file detected, dSYM was created with an executable with no debug info.
Process 19325 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1009eae78)
       frame #0: 0x00000001009eae78 libruby.4.0.dylib`rb_parser_enc_cr_str_buf_cat + 432
libruby.4.0.dylib`rb_parser_enc_cr_str_buf_cat:
->  0x1009eae78 <+432>: brk    #0x1

libruby.4.0.dylib`parser_yylex:
    0x1009eae7c <+0>:   sub    sp, sp, #0xf0
    0x1009eae80 <+4>:   stp    x28, x27, [sp, #0x90]
    0x1009eae84 <+8>:   stp    x26, x25, [sp, #0xa0]
Target 0: (ruby) stopped.

No data to display

Actions

Also available in: PDF Atom