Issue #10877 has been reported by Wei-Hang Jian.

----------------------------------------
Bug #10877: String#sub causes segfault
https://bugs.ruby-lang.org/issues/10877

* Author: Wei-Hang Jian
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.2.0
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
str = 'abc'
reg = /(?<foo>a)bc/
str =~ reg
$~['foo'].sub 'a', ''
$~['foo']
~~~

~~~
tmp.rb:5: [BUG] Segmentation fault at 0x00000000000020
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/CrashReporter
     * /Library/Logs/CrashReporter
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0010 e:000009 CFUNC  :[]
c:0002 p:0042 s:0006 E:0007a0 EVAL   tmp.rb:5 [FINISH]
c:0001 p:0000 s:0002 E:002250 TOP    [FINISH]

-- Ruby level backtrace information ----------------------------------------
tmp.rb:5:in `<main>'
tmp.rb:5:in `[]'

-- Machine register context ------------------------------------------------
 rax: 0x0000000000000008 rbx: 0x00007f8d09061048 rcx: 0x000000000050c005
 rdx: 0x0000000000000005 rdi: 0x00007fff5584a180 rsi: 0x000000010a6d5038
 rbp: 0x00007fff5584a1a0 rsp: 0x00007fff5584a170  r8: 0x0000000000000001
  r9: 0x0000000000000000 r10: 0x0000000000000001 r11: 0x0000000000000000
 r12: 0x000000010a7d4f60 r13: 0x000000010a7d4f60 r14: 0x00007f8d09061290
 r15: 0x000000010a6d5038 rip: 0x000000010a49cfa0 rfl: 0x0000000000010202

-- C level backtrace information -------------------------------------------
0   ruby                                0x000000010a54dd3b rb_vm_bugreport + 155
1   ruby                                0x000000010a3f4c50 rb_bug_context + 480
2   ruby                                0x000000010a4ca873 sigsegv + 83
3   libsystem_platform.dylib            0x00007fff8c973f1a _sigtramp + 26
4   ruby                                0x000000010a49cfa0 match_aref + 224
5   ???                                 0x00007fff5584a1a0 0x0 + 140734628143520

-- Other runtime information -----------------------------------------------

* Loaded script: tmp.rb

* Loaded features:

    0 enumerator.so
    1 rational.so
    2 complex.so
    3 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/x86_64-darwin14/enc/encdb.bundle
    4 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/x86_64-darwin14/enc/trans/transdb.bundle
    5 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/unicode_normalize.rb
    6 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/x86_64-darwin14/rbconfig.rb
    7 thread.rb
    8 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/x86_64-darwin14/thread.bundle
    9 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/compatibility.rb
   10 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/defaults.rb
   11 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/deprecate.rb
   12 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/errors.rb
   13 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/version.rb
   14 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/requirement.rb
   15 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/platform.rb
   16 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/basic_specification.rb
   17 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/stub_specification.rb
   18 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/util/stringio.rb
   19 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/specification.rb
   20 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/exceptions.rb
   21 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
   22 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/monitor.rb
   23 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
   24 /Users/tonytonyjan/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
Don't forget to include the above Crash Report log file.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap: 6
~~~



-- 
https://bugs.ruby-lang.org/