Project

General

Profile

Actions

Backport #6304

closed

JSON.parse with :object_class still causes SEGV

Added by juanje (Juanje Ojeda) over 12 years ago. Updated over 12 years ago.

Status:
Closed
[ruby-core:44382]

Description

=begin
I couldn't reopen the bug #5846 so I created this one, but actually is the same bug which seems to me not fixed.

I got ((|JSON.parse|)) working with some ((|Hash|)) alike classes as ((|Mash|)):

$ ruby -rjson -rmash -e 'p JSON.parse("{"key":"value"}", :object_class => Mash)'

And failing as expected with non ((|Hash|)) alike class as ((|Set|)):

$ ruby -rjson -rset -e 'p JSON.parse("{"key":"value"}", :object_class => Set)'
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148:in parse': undefined method []=' for #<Set: {}> (NoMethodError)
from /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148:in parse' from -e:1:in '

This was behaving like that before.

But when I try with another ((|Hash|)) alike class, ((|Chef::Node|)), is crash as the previous bug says:

$ ruby -rjson -e 'require "chef/node"; p JSON.parse("{"key":"value"}", :object_class => Chef::Node)'
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148: [BUG] Segmentation fault
ruby 1.9.3p184 (2012-04-15 revision 35335) [i686-linux]

-- Control frame information -----------------------------------------------
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :parse
c:0004 p:0031 s:0012 b:0012 l:000011 d:000011 METHOD /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148
c:0003 p:0043 s:0007 b:0006 l:000e14 d:00163c EVAL -e:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000e14 d:000e14 TOP

-- Ruby level backtrace information ----------------------------------------
-e:1:in <main>' /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148:in parse'
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb:148:in `parse'

-- C level backtrace information -------------------------------------------
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x17f03a) [0xb779603a] vm_dump.c:796
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x52ae3) [0xb7669ae3] error.c:258
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(rb_bug+0x44) [0xb766a804] error.c:277
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x10e76c) [0xb772576c] signal.c:609
[0xb784e40c]
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(st_lookup+0xe) [0xb772d23e] st.c:326
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(rb_hash_aref+0x3d) [0xb768724d] hash.c:512
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/json/ext/parser.so(+0x252d) [0xb760652d] parser.rl:169
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/json/ext/parser.so(+0x2f59) [0xb7606f59] parser.rl:711
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x16a01d) [0xb778101d] vm_insnhelper.c:320
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x178397) [0xb778f397] vm_insnhelper.c:404
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x16f56f) [0xb778656f] insns.def:1015
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x174533) [0xb778b533] vm.c:1220
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(rb_iseq_eval_main+0xb5) [0xb77912b5] vm.c:1461
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(+0x56854) [0xb766d854] eval.c:204
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(ruby_exec_node+0x24) [0xb766e6c4] eval.c:251
/home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/libruby.so.1.9(ruby_run_node+0x36) [0xb7670636] eval.c:244
ruby() [0x8048658]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0xb74a0113]
ruby() [0x8048681]

-- Other runtime information -----------------------------------------------

  • Loaded script: -e

  • Loaded features:

    0 enumerator.so
    1 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/encdb.so
    2 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so
    3 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb
    4 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/rbconfig.rb
    5 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb
    6 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb
    7 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
    8 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems.rb
    9 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/version.rb
    10 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/common.rb
    11 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/utf_16be.so
    12 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/utf_16le.so
    13 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/utf_32be.so
    14 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/enc/utf_32le.so
    15 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/json/ext/parser.so
    16 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/i686-linux/json/ext/generator.so
    17 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json/ext.rb
    18 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/json.rb
    ...
    117 /home/jojeda/.rvm/gems/ruby-1.9.3-head/gems/chef-0.10.8/lib/chef/run_list/run_list_expansion.rb
    118 /home/jojeda/.rvm/gems/ruby-1.9.3-head/gems/chef-0.10.8/lib/chef/run_list/versioned_recipe_list.rb
    119 /home/jojeda/.rvm/gems/ruby-1.9.3-head/gems/chef-0.10.8/lib/chef/run_list.rb
    120 /home/jojeda/.rvm/gems/ruby-1.9.3-head/gems/chef-0.10.8/lib/chef/node/attribute.rb
    121 /home/jojeda/.rvm/gems/ruby-1.9.3-head/gems/chef-0.10.8/lib/chef/node.rb

  • Process memory map:

08048000-08049000 r-xp 00000000 08:01 5388946 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/bin/ruby
08049000-0804a000 r--p 00000000 08:01 5388946 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/bin/ruby
0804a000-0804b000 rw-p 00001000 08:01 5388946 /home/jojeda/.rvm/rubies/ruby-1.9.3-head/bin/ruby
091c0000-09d9b000 rw-p 00000000 00:00 0 [heap]
...
b784e000-b784f000 r-xp 00000000 00:00 0 [vdso]
b784f000-b786d000 r-xp 00000000 08:06 263112 /lib/i386-linux-gnu/ld-2.13.so
b786d000-b786e000 r--p 0001d000 08:06 263112 /lib/i386-linux-gnu/ld-2.13.so
b786e000-b786f000 rw-p 0001e000 08:06 263112 /lib/i386-linux-gnu/ld-2.13.so
bfc1b000-bfc3c000 rw-p 00000000 00:00 0 [stack]

[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

I put the full trace at ((<pastebin link|URL:http://pastebin.com/pEwxMij0>)) to avoid the noise.

The ((Chef::Node|URL:https://github.com/opscode/chef/blob/master/chef/lib/chef/node.rb#L250)) class implements the methods (({[]})) and (({[]=})). And don't not if they need anything else to be working, but anyways it should fails nicer rather than crash like that, shouldn't it?

Thanks for your time and I hope this help to improve it.

=end


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #5846: JSON.parse with :object_class causes SEGVClosednaruse (Yui NARUSE)01/05/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0