Project

General

Profile

Bug #15489

SEGV when using refinements and `&:` syntax

Added by sue445 (Go Sueyoshi) 23 days ago. Updated 22 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-dev:50741]

Description

Sample code

# segv.rb

module ArrayExt
  refine Array do
  end
end

class MyHash
  def initialize(hash = {})
    @hash = hash
  end

  def method_missing(key)
    if @hash.key?(key)
      @hash[key]
    else
      super
    end
  end

  def respond_to_missing?(method_name, include_private = false)
    @hash.keys.include?(method_name) || super
  end
end

using ArrayExt

tags = [
  MyHash.new(name: "v1.0.0"),
  MyHash.new(name: "v1.0.1"),
]

# p tags.map{ |tag| tag.name } # this is OK
p tags.map(&:name)

Expected

no error

Actual

$ ruby segv.rb
segv.rb:32: [BUG] Segmentation fault at 0x0000000000000008
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin16]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0004 p:---- s:0015 e:000014 IFUNC
c:0003 p:---- s:0012 e:000011 CFUNC  :map
c:0002 p:0065 s:0008 E:001488 EVAL   segv.rb:32 [FINISH]
c:0001 p:0000 s:0003 E:0026f0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
segv.rb:32:in `<main>'
segv.rb:32:in `map'

-- Machine register context ------------------------------------------------
 rax: 0x0000000000000000 rbx: 0x00007fff541e6d10 rcx: 0xd5c0433e961c0053
 rdx: 0x00007fff541e6b78 rdi: 0x00000000000004e2 rsi: 0x000000000000008f
 rbp: 0x00007fff541e6c50 rsp: 0x00007fff541e6bc0  r8: 0x00007f8be3806000
  r9: 0x000000000000001f r10: 0x00007f8be2c17110 r11: 0x0000000000000130
 r12: 0x00007f8be31e0d40 r13: 0x0000000000000008 r14: 0x0000000000001131
 r15: 0x0000000000000000 rip: 0x000000010bc300b1 rfl: 0x0000000000010206

-- C level backtrace information -------------------------------------------
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(rb_vm_bugreport+0x82) [0x10bc36442]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10ba98598) [0x10ba98598]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bba14c1) [0x10bba14c1]
/usr/lib/system/libsystem_platform.dylib(_sigtramp+0x1a) [0x7fff981c8b3a]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc300b1) [0x10bc300b1]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc31bcd) [0x10bc31bcd]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc1dd8e) [0x10bc1dd8e]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10ba22e57) [0x10ba22e57]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc29c1b) [0x10bc29c1b]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc11ee0) [0x10bc11ee0]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10bc248ac) [0x10bc248ac]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10baa3338) [0x10baa3338]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10baa31c9) [0x10baa31c9]
/Users/sue445/.rbenv/versions/2.6.0/bin/ruby(0x10ba1974d) [0x10ba1974d]

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

* Loaded script: segv.rb

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/encdb.bundle
    5 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/trans/transdb.bundle
    6 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/rbconfig.rb
    7 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/compatibility.rb
    8 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/defaults.rb
    9 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/deprecate.rb
   10 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/errors.rb
   11 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/version.rb
   12 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/requirement.rb
   13 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/platform.rb
   14 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/basic_specification.rb
   15 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/stub_specification.rb
   16 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/delegate.rb
   17 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/rfc2396_parser.rb
   18 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/rfc3986_parser.rb
   19 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/common.rb
   20 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/generic.rb
   21 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/file.rb
   22 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/ftp.rb
   23 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/http.rb
   24 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/https.rb
   25 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/ldap.rb
   26 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/ldaps.rb
   27 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri/mailto.rb
   28 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/uri.rb
   29 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/specification_policy.rb
   30 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/util/list.rb
   31 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/stringio.bundle
   32 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/specification.rb
   33 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/exceptions.rb
   34 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/util.rb
   35 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb
   36 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/dependency.rb
   37 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_gem.rb
   38 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/monitor.rb
   39 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb
   40 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_warn.rb
   41 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems.rb
   42 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/path_support.rb
   43 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/version.rb
   44 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/core_ext/name_error.rb
   45 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/levenshtein.rb
   46 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/jaro_winkler.rb
   47 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checker.rb
   48 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
   49 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
   50 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/name_error_checkers.rb
   51 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/method_name_checker.rb
   52 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/key_error_checker.rb
   53 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/spell_checkers/null_checker.rb
   54 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean/formatters/plain_formatter.rb
   55 /Users/sue445/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/did_you_mean-1.3.0/lib/did_you_mean.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: https://www.ruby-lang.org/bugreport.html

[IMPORTANT]
Don't forget to include the Crash Report log file under
DiagnosticReports directory in bug reports.

Abort trap: 6

This behavior is same to ruby-trunk

$ ruby -v
ruby 2.7.0dev (2018-12-30 trunk 66652) [x86_64-darwin16]

I attached crash log.

Workaround

  • Use map { |tag| tag.name } instead of map(&:name) .
  • Avoid refinements. (Remove using ArrayExt)

Files

crash_log.txt (28.7 KB) crash_log.txt sue445 (Go Sueyoshi), 12/30/2018 11:03 AM

Associated revisions

Revision f964fd3f
Added by nobu (Nobuyoshi Nakada) 22 days ago

vm_args.c: search symbol proc in super classes

  • vm_args.c (refine_sym_proc_call): traverse ancestors to search inherited methods for symbol proc. [ruby-dev:50741] [Bug #15489]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 66658
Added by nobu (Nobuyoshi Nakada) 22 days ago

vm_args.c: search symbol proc in super classes

  • vm_args.c (refine_sym_proc_call): traverse ancestors to search inherited methods for symbol proc. [ruby-dev:50741] [Bug #15489]

History

#1

Updated by nobu (Nobuyoshi Nakada) 22 days ago

  • Status changed from Open to Closed

Applied in changeset trunk|r66658.


vm_args.c: search symbol proc in super classes

  • vm_args.c (refine_sym_proc_call): traverse ancestors to search inherited methods for symbol proc. [ruby-dev:50741] [Bug #15489]

Also available in: Atom PDF