Projects

Ticket #527 (new defect)

Opened 2 years ago

Last modified 14 months ago

Segmentation fault when stack overflows

Reported by: haruki.zaemon@… Owned by: lsansonetti@…
Priority: major Milestone: MacRuby Later
Component: MacRuby Keywords: stack overflow segfault
Cc: haruki.zaemon@…

Description (last modified by lsansonetti@…) (diff)

irb --> def a(n); n == 0 ? "DONE" : b(n - 1); end
irb --> def b(n); n == 0 ? "DONE" : a(n - 1); end
irb --> a(10000)
Segmentation fault

Change History

follow-up: ↓ 5   Changed 2 years ago by conradwt@…

This is a very common case in both Ruby 1.8.x and 1.9.x. In Ruby 1.9.1, the max stack is set by the interpreter. This may or may not be the case in MacRuby.

  Changed 2 years ago by lsansonetti@…

  • description modified (diff)

  Changed 2 years ago by lsansonetti@…

I guess we should not crash and raise an exception instead.

  Changed 2 years ago by conradwt@…

Yes, I agree that MacRuby should generate an exception. For example, in Ruby 1.9.1/1.9.2, the following is generated:

$ ruby stack-overflow.rb 
stack-overflow.rb:6:in `b': stack level too deep (SystemStackError)
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:6:in `b'
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:6:in `b'
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:6:in `b'
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:6:in `b'
	 ... 8718 levels...
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:6:in `b'
	from stack-overflow.rb:2:in `a'
	from stack-overflow.rb:9:in `<main>'

in reply to: ↑ 1   Changed 2 years ago by haruki.zaemon@…

Replying to conradwt@…:

This is a very common case in both Ruby 1.8.x and 1.9.x. In Ruby 1.9.1, the max stack is set by the interpreter. This may or may not be the case in MacRuby.

Sorry, perhaps I should have been more specific: I think an exception should be raised (as is done in MRI and Rubinius) rather than a segmentation fault.

  Changed 2 years ago by haruki.zaemon@…

  • cc haruki.zaemon@… added

Cc Me!

  Changed 18 months ago by martinlagardette@…

Updating status of the bug following #822:

It could be possible for MacRuby to handle stack overflow, by handling the stack overflow signal in an alternate stack (allocated with sigaltstack).

The reasons it is not currently in MacRuby are

  • Handling the stack overflow signal (I believe it is SIGSEV) messes up the stack and is not good for crash trace analyzers (See r4077)
  • If we raise in the alt stack, I'm not sure there's a way to catch it in the main thread, meaning a SystemStackError would stop the program, and would not be catchable

  Changed 18 months ago by lsansonetti@…

Catching the signal wouldnt help here as I'm pretty sure it's already too late to do anything, also, sending an exception from a signal handler isn't likely to work too.

What we could do instead is keep a counter in the dispatch cache. However I don't think this is a critical issue.

  Changed 18 months ago by martinlagardette@…

"Catching the signal wouldnt help here as I'm pretty sure it's already too late to do anything"

That's actually what sigaltstack is for, it allocates a stack just for handling the signal. But yeah, raising from there is likely to fail.

And I also agree that it's not a critical issue at all, I just wanted to update the status of the bug so that people know why it's not fixed yet :-)

  Changed 14 months ago by lsansonetti@…

  • milestone set to MacRuby Later

For Later.

Note: See TracTickets for help on using tickets.