Actions
Bug #18084
closed`JSON.dump` can crash VM.
Description
require 'json'
x = {}; x[:x] = x
JSON.dump(x) # => nil
JSON.dump(x) # => SIGILL
Results from our friendly all ruby bot:
:x: 1.8
-:1:in `require': no such file to load -- json (LoadError)
from -:1
exit: 1
:x: 1.9
/build-all-ruby/1.9.3-p551/lib/ruby/1.9.1/json/common.rb:216: stack level too deep (SystemStackError)
exit: 1
:x: 2.0
/build-all-ruby/2.0.0-p648/lib/ruby/2.0.0/json/common.rb:224: stack level too deep (SystemStackError)
exit: 1
:x: 2.1
/build-all-ruby/2.1.10/lib/ruby/2.1.0/json/common.rb:223: stack level too deep (SystemStackError)
exit: 1
:x: 2.2
/build-all-ruby/2.2.10/lib/ruby/2.2.0/json/common.rb:223:in `encode': stack level too deep (SystemStackError)
from /build-all-ruby/2.2.10/lib/ruby/2.2.0/json/common.rb:223:in `generate'
from /build-all-ruby/2.2.10/lib/ruby/2.2.0/json/common.rb:223:in `generate'
from /build-all-ruby/2.2.10/lib/ruby/2.2.0/json/common.rb:394:in `dump'
from -:5:in `<main>'
Show more
exit: 1
:x: 2.3
/build-all-ruby/2.3.8/lib/ruby/2.3.0/json/common.rb:224:in `encode': stack level too deep (SystemStackError)
from /build-all-ruby/2.3.8/lib/ruby/2.3.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.3.8/lib/ruby/2.3.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.3.8/lib/ruby/2.3.0/json/common.rb:395:in `dump'
from -:5:in `<main>'
Show more
exit: 1
:x: 2.4
/build-all-ruby/2.4.10/lib/ruby/2.4.0/json/common.rb:224:in `encode': stack level too deep (SystemStackError)
from /build-all-ruby/2.4.10/lib/ruby/2.4.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.4.10/lib/ruby/2.4.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.4.10/lib/ruby/2.4.0/json/common.rb:394:in `dump'
from -:5:in `<main>'
Show more
exit: 1
:x: 2.5
/build-all-ruby/2.5.8/lib/ruby/2.5.0/json/common.rb:224:in `generate': stack level too deep (SystemStackError)
from /build-all-ruby/2.5.8/lib/ruby/2.5.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.5.8/lib/ruby/2.5.0/json/common.rb:394:in `dump'
from -:5:in `<main>'
exit: 1
:x: 2.6
/build-all-ruby/2.6.6/lib/ruby/2.6.0/json/common.rb:224:in `generate': stack level too deep (SystemStackError)
from /build-all-ruby/2.6.6/lib/ruby/2.6.0/json/common.rb:224:in `generate'
from /build-all-ruby/2.6.6/lib/ruby/2.6.0/json/common.rb:394:in `dump'
from -:5:in `<main>'
exit: 1
:x: 2.7 -- 58bd943436 (2021-08-17T17:25:19Z)
-: machine stack overflow in critical region (fatal)
exit: 1
So in the best case, we got SystemStackError
, and from 2.7+ we get a fatal error.
Do we want to improve this behaviour or is this expected, and if so, should we add documentation to this effect?
Actions
Like0
Like0Like0Like0Like0Like0