Skip to content

Instantly share code, notes, and snippets.

@mbj
Last active September 28, 2017 17:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbj/31163a8e712573877268 to your computer and use it in GitHub Desktop.
Save mbj/31163a8e712573877268 to your computer and use it in GitHub Desktop.
segfault.rb
class Foo
include Enumerable
def each(&block)
[].__send__(:each, &block)
rescue Exception
end
def more
to_a # any method from enumerable
[self]
end
end
def call(resource)
resource.more.each(&method(__method__))
end
Thread.new do
Kernel.catch(Exception.new) do
call(Foo.new)
end
end.join
# It is expected to:
# a) Raise a system stack error (expected)
# b) Segfault (Bug in MRI I'm hunting)
# c) Hang (Serve bug in MRI I'm hunting) please also check via strace / gdb if a segfault happened and the signal handler is trapped in a futex
# Context: https://github.com/mbj/mutant/issues/265
@mbj
Copy link
Author

mbj commented Jan 31, 2015

This problem was probably solved with: ruby/ruby@8fe95fe

@kbrock
Copy link

kbrock commented Sep 22, 2015

2.2.3 and 2.2.2 give me the same results.

ruby segfault.rb 
segfault.rb:10:in `to_a': stack level too deep (SystemStackError)
    from segfault.rb:10:in `more'
    from segfault.rb:16:in `call'
    from segfault.rb:16:in `each'
    from segfault.rb:16:in `call'
    from segfault.rb:16:in `each'
    from segfault.rb:16:in `call'
    from segfault.rb:16:in `each'
    from segfault.rb:16:in `call'
     ... 1189 levels...
    from segfault.rb:16:in `call'
    from segfault.rb:21:in `block (2 levels) in <main>'
    from segfault.rb:20:in `catch'
    from segfault.rb:20:in `block in <main>'
ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

of note, 2.3dev just hangs for me.

@mathieujobin
Copy link

mathieujobin commented Sep 28, 2017

[mathieu@hz550 loyalty]$ rvm use 2.2.8
Using /home/mathieu/.rvm/gems/ruby-2.2.8
[mathieu@hz550 loyalty]$ ruby  segfault.rb
segfault.rb:10:in `to_a': stack level too deep (SystemStackError)
        from segfault.rb:10:in `more'
        from segfault.rb:16:in `call'
        from segfault.rb:16:in `each'
        from segfault.rb:16:in `call'
        from segfault.rb:16:in `each'
        from segfault.rb:16:in `call'
        from segfault.rb:16:in `each'
        from segfault.rb:16:in `call'
         ... 1103 levels...
        from segfault.rb:16:in `call'
        from segfault.rb:21:in `block (2 levels) in <main>'
        from segfault.rb:20:in `catch'
        from segfault.rb:20:in `block in <main>'
[mathieu@hz550 loyalty]$ ruby -v 
ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux]
[mathieu@hz550 loyalty]$ rvm use 2.3.5
Using /home/mathieu/.rvm/gems/ruby-2.3.5
[mathieu@hz550 loyalty]$ ruby  segfault.rb
segfault.rb:10:in `to_a': stack level too deep (SystemStackError)
        from segfault.rb:10:in `more'
        from segfault.rb:16:in `call'
        from segfault.rb:16:in `each'                                                                                                                                                
        from segfault.rb:16:in `call'                                                                                                                                                
        from segfault.rb:16:in `each'                                                                                                                                                
        from segfault.rb:16:in `call'                                                                                                                                                
        from segfault.rb:16:in `each'                                                                                                                                                
        from segfault.rb:16:in `call'                                                                                                                                                
         ... 809 levels...                                                                                                                                                           
        from segfault.rb:16:in `call'                                                                                                                                                
        from segfault.rb:21:in `block (2 levels) in <main>'                                                                                                                          
        from segfault.rb:20:in `catch'                                                                                                                                               
        from segfault.rb:20:in `block in <main>'                                                                                                                                     
[mathieu@hz550 loyalty]$ rvm use 2.4.2
Using /home/mathieu/.rvm/gems/ruby-2.4.2
[mathieu@hz550 loyalty]$ ruby  segfault.rb
segfault.rb:10: [BUG] vm_call_cfunc - cfp consistency error
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

-- Control frame information -----------------------------------------------
Segmentation fault (core dumped)
[mathieu@hz550 loyalty]$ 

ArchLinux 64bit
Linux hz550 4.12.12-1-ARCH #1 SMP PREEMPT Sun Sep 10 09:41:14 CEST 2017 x86_64 GNU/Linux

on debian 14.04 I am getting segfault.rb:10: [BUG] vm_call_cfunc - cfp consistency error on 2.2.8

@mathieujobin
Copy link

mathieujobin commented Sep 28, 2017

mathieu@ubuntu-1404 (i-123):~$ ruby segfault.rb 
Segmentation fault (core dumped)                                                                                                                                                     
mathieu@ubuntu-1404 (i-123):~$    

with brighbox compiled packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment