Project

General

Profile

Actions

Bug #9454

closed

The define_method(:class) segfault

Bug #9454: The define_method(:class) segfault

Added by kyrylo (Kyrylo Silin) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
[ruby-core:60113]

Description

Ruby 2.1.0p0 segfaults when I invoke the following code.

define_method(:class) { self.class }
self.class #=> segfault :(

It affects exclusively Ruby 2.1.0p0 (I also tested on the most recent 2.0.0, 1.9.3 and 1.8.7).

By the way, on the contrary, the following code does not segfault.

def self.class; self.class end
self.class #=> SystemStackError

Viva la Ucraino revolución!


Files

bug9454.txt (625 KB) bug9454.txt kyrylo (Kyrylo Silin), 01/26/2014 07:25 PM

Related issues 4 (0 open4 closed)

Related to Ruby - Bug #14387: Ruby 2.5 を Alpine Linux で実行すると比較的浅めで SystemStackError 例外になるClosedActions
Has duplicate Ruby - Bug #9945: Segmentation fault when defining recursive methodClosedActions
Has duplicate Ruby - Bug #10218: 手続きを再帰するとSegmentation faultが発生するClosedActions
Has duplicate Ruby - Bug #10955: invoke_block_from_c segfaultClosedActions

Updated by kyrylo (Kyrylo Silin) over 11 years ago Actions #1 [ruby-core:60114]

Here's the log with the segfault.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #2 [ruby-core:60116]

Seems an infinite recursion, obviously.

Updated by kyrylo (Kyrylo Silin) over 11 years ago Actions #3 [ruby-core:60118]

Sure. As far as I understand it should raise a SystemStackError instead of segfaulting (that's how it worked before v2.1.0p0). If you could give me a hint, which file is relevant, I would probably come up with a patch (I don't promise anything, because I'm not very good at C and Ruby internals).

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #4 [ruby-core:60120]

At first glan.ce, it occurred in INSNS_DISPATCH() macro.
Considering that the second case works fine, maybe recovery jump fails.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #5 [ruby-core:60138]

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r44712.


thread_pthread.c: get current main thread stack size

  • thread_pthread.c: get current main thread stack size, which may
    be expanded than allocated size at initialization, by rlimit().
    [ruby-core:60113] [Bug #9454]

Updated by normalperson (Eric Wong) over 11 years ago Actions #6 [ruby-core:60248]

Btw, TestException#test_machine_stackoverflow_by_define_method fails
on an ancient glibc 2.5-42.el5_4.3 (CentOS 5.4 x86_64).

I think this is a bug in pthread_getattr_np when it is run on the main
thread. I'm not sure how many people care about a platform this old,
though; and I've been meaning to upgrade that anyways.

Updated by ReiOdaira (Rei Odaira) over 11 years ago Actions #7 [ruby-core:61829]

FYI, TestException#test_machine_stackoverflow_by_define_method fails on my environment, too: Linux 2.6.32-71.el6.x86_64 and glibc 2.12-1.7.el6.

$ ruby -v
ruby 2.2.0dev (2014-04-01 trunk 45498) [x86_64-linux]

The problem is that pthread_attr_getstack() and even getrlimit() return 0xa00000 (= 10 MB) as a max stack size, but the actual stack size at the time of the stack overflow seems bigger by about 2 MB, according to /proc/PID/maps.

7fe1f7664000-7fe1f7afe000 rw-p 00000000 00:00 0                          [heap]
7fffc0836000-7fffc1435000 rw-p 00000000 00:00 0                          [stack]
7fffc15d4000-7fffc15d5000 r-xp 00000000 00:00 0                          [vdso]

0x7fffc1435000 - 0x7fffc1435000 = 0xbff000 (= ~12 MB). As a result, the address causing SIGSEGV is not considered as part of the stack.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #9 [ruby-core:63178]

  • Has duplicate Bug #9945: Segmentation fault when defining recursive method added

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #10 [ruby-core:63234]

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago Actions #11 [ruby-core:63255]

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: REQUIRED to 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: DONE

r44712, r44715, r44716, r44722, r44725, r44726 and r44753 were backported into ruby_2_1 branch at r46468.

Updated by usa (Usaku NAKAMURA) over 11 years ago Actions #12 [ruby-core:63535]

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: DONE to 1.9.3: UNKNOWN, 2.0.0: DONE, 2.1: DONE

backported into ruby_2_0_0 at r46667 and r46669.

Updated by usa (Usaku NAKAMURA) over 11 years ago Actions #13 [ruby-core:63540]

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: DONE, 2.1: DONE to 1.9.3: UNKNOWN, 2.0.0: REQUIRED, 2.1: DONE

... but reverted because it introduced SEGV on CentOS.
Maybe somthing is missed, but I wasn't able to find it.

Updated by nagachika (Tomoyuki Chikanaga) about 11 years ago Actions #14 [ruby-core:65038]

  • Has duplicate Bug #10218: 手続きを再帰するとSegmentation faultが発生する added

Updated by nobu (Nobuyoshi Nakada) over 10 years ago Actions #15

  • Has duplicate Bug #10955: invoke_block_from_c segfault added

Updated by wanabe (_ wanabe) over 7 years ago Actions #16

  • Related to Bug #14387: Ruby 2.5 を Alpine Linux で実行すると比較的浅めで SystemStackError 例外になる added
Actions

Also available in: PDF Atom