Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Code Bug causes SegFault #1269

Closed
levmatta-umanni opened this Issue · 3 comments

4 participants

@levmatta-umanni

I have been tracking this bug for quite some time with the Ruby Core Issue#5986 team and then with EventMachine Issue#318.

It turns out that an infinite loop is caused by and Arbre::HTML::Element#to_ary method, as explained by note #13.
It seams that this is somewhat out of place.

Please Verify.

@latortuga

Relevant portion of the linked issue on Ruby Core for those interested:

Arbre::HTML::Element (which is defined in active_admin) defines #to_ary wrongly, as the class does not mimic Array class. https://github.com/gregbell/active_admin/blob/master/lib/active_admin/arbre/html/element.rb#L147

  def to_ary
    Collection.new [self]
  end

(The Collection class inherits Array). And, an instance of the class is passed to Kernel.puts, which cause a bug.

In short, this is considered like the following small code:

class Foo
  def to_ary
    Array.new [self]
  end
end
puts Foo.new

(This code does not cause SEGV in my 32 bit system, but naruse said
it does in x86_64)

This causes infinite recursion, which leads to stack overflow.
This behavior can be also observed in the following stack trace:

I played around with this a little bit on my system (32-bit ubuntu) and it does segfault with the example code he posted (on 1.9.3-p125, latest 1.9.3 I think).

If you just define to_a instead of to_ary, everything works fine. I have not run the test suite but that seems like the fix to me.

@jancel

Changing to_ary to to_a fails a bunch of tests, I'm going to look into some stuff, may be a fun learning experience.

@jpmckinney

Arbre is now external to activeadmin. Please open issue there if still a problem https://github.com/gregbell/arbre

@jpmckinney jpmckinney closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.