Project

General

Profile

Actions

Bug #2133

closed

Segfault When Eval'ing Large Hash Literals

Added by runpaint (Run Paint Run Run) about 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2009-09-11) [i686-linux]
Backport:
[ruby-core:25714]

Description

=begin
I can reproduce a segfault on ruby 1.9.2dev (2009-09-11) [i686-linux] by creating a hash with many thousands of keys, then eval'ing the result.

$ cat /tmp/large-hash.rb
hash = {}
IO.foreach('/usr/share/dict/words') do |line|
hash[line] = line.size
end
p "Hashed #{hash.keys.size} keys"
eval <<EOF
class C
@@h = #{hash.inspect}
end
EOF

$ ruby /tmp/large-hash.rb
"Hashed 638311 keys"
(eval):2: [BUG] Segmentation fault
ruby 1.9.2dev (2009-09-11) [i686-linux]

-- control frame ----------
c:0007 p:261966 s:302922756 b:0017 l:000016 d:000016 CLASS (eval):2
c:0006 p:0009 s:0015 b:0015 l:00080c d:000014 EVAL (eval):1
c:0005 p:---- s:0013 b:0013 l:000012 d:000012 FINISH
c:0004 p:---- s:0011 b:0011 l:000010 d:000010 CFUNC :eval
c:0003 p:0078 s:0007 b:0007 l:00080c d:000ea8 EVAL /tmp/large-hash.rb:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:00080c d:00080c TOP

/tmp/large-hash.rb:6:in <main>' /tmp/large-hash.rb:6:in eval'
(eval):1:in <main>' (eval):2:in class:C'

-- C level backtrace information -------------------------------------------
ruby(rb_vm_bugreport+0xb5) [0x8167535]
ruby [0x81a3fcb]
ruby(rb_bug+0x28) [0x81a4058]
ruby [0x80fb585]
[0xb7f29410]
ruby [0x815e884]
ruby [0x815f5c0]
ruby(rb_f_eval+0xe1) [0x815fbd1]
ruby [0x81537cd]
ruby [0x8153919]
ruby [0x8165555]
ruby [0x81595fd]
ruby [0x815e884]
ruby(rb_iseq_eval_main+0x1a3) [0x815eb73]
ruby(ruby_exec_node+0x97) [0x805d797]
ruby(ruby_run_node+0x46) [0x805f0d6]
ruby(main+0x60) [0x805cbb0]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7d49775]
ruby [0x805cab1]

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

(My dictionary is 6.5MB, so I haven't attached it.)

The same problem is encountered when the contents of the heredoc is piped to a file which is then require'd, also.

It is relevant that the hash is instantiated inside of a class; in the example below a segfault does not occur:

$ cat /tmp/large-hash.rb
hash = {}
IO.foreach('/usr/share/dict/words') do |line|
hash[line] = line.size
end
p "Hashed #{hash.keys.size} keys"
eval "h = #{hash.inspect}"

$ ruby /tmp/large-hash.rb
"Hashed 638311 keys"
(eval):0:in <main>': stack level too deep (SystemStackError) from /tmp/large-hash.rb:6:in eval'
from /tmp/large-hash.rb:6:in `'
=end

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

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

=begin
Applied in changeset r25048.
=end

Actions

Also available in: Atom PDF

Like0
Like0