Hash#inspect segfaults when inspecting self-referential Hashes #57

Closed
postmodern opened this Issue Apr 26, 2012 · 4 comments

Comments

Projects
None yet
2 participants
h = Hash.new
h[1] = h
puts h.inspect

Expected Result: {1=>{...}}

Actual Result: Segfault

Backtrace:

Program terminated with signal 11, Segmentation fault.
#0  0x000000000044d3bb in kh_get_n2s (h=0x240b878, key=0x4c9a30 "TypeError")
    at ../../src/symbol.c:27
27  KHASH_MAP_INIT_STR(n2s, mrb_sym);
(gdb) bt
#0  0x000000000044d3bb in kh_get_n2s (h=0x240b878, key=0x4c9a30 "TypeError")
    at ../../src/symbol.c:27
#1  0x000000000044d74a in mrb_intern (mrb=0x23b9010, name=0x4c9a30 "TypeError")
    at ../../src/symbol.c:40
#2  0x000000000047b92a in mrb_class_obj_get (mrb=0x23b9010, name=0x4c9a30 "TypeError")
    at ../../src/variable.c:456
#3  0x000000000043e386 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#4  0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2edf0 "arena overflow error", len=20) at ../../src/string.c:624
#5  0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 
    ptr=0x7fff71a2edf0 "arena overflow error", len=20) at ../../src/error.c:35
#6  0x0000000000416cc4 in mrb_raise (mrb=0x23b9010, c=0x23c4e78, 
    fmt=0x4c9a3a "arena overflow error") at ../../src/error.c:209
#7  0x000000000043e3a2 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#8  0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2f140 "arena overflow error", len=20) at ../../src/string.c:624
#9  0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 
    ptr=0x7fff71a2f140 "arena overflow error", len=20) at ../../src/error.c:35
#10 0x0000000000416cc4 in mrb_raise (mrb=0x23b9010, c=0x23c4e78, 
    fmt=0x4c9a3a "arena overflow error") at ../../src/error.c:209
#11 0x000000000043e3a2 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#12 0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2f490 "arena overflow error", len=20) at ../../src/string.c:624
#13 0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 
Owner

matz commented Apr 26, 2012

If we try to detect recursive data structure, the program became safer but the interpreter will be bigger.
mruby takes smaller program size than safety. I don't call it a spec but limitation, for now, at least.

matz closed this Apr 26, 2012

It appears mruby correctly handles recursive Arrays. Maybe Hash#inspect could simply check if a value has the same object_id as the Hash itself?

Owner

matz commented Apr 26, 2012

Actually I was about to remove the array code to reduce the size.
Do you really need the recursive detection?

That makes sense. Having consistent behaviour is more important.

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