ActionsLike0
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?
Updated by ioquatix (Samuel Williams) over 3 years ago
- Description updated (diff)
Minor improvement to formatting.
Updated by mame (Yusuke Endoh) over 3 years ago
- Related to Bug #5808: "a = []; a << a; puts JSON.dump(a)" aborted added
Updated by ioquatix (Samuel Williams) over 3 years ago
@nobu (Nobuyoshi Nakada) suggested the following code could be updated:
sigill(int sig SIGINFO_ARG)
{
check_reserved_signal("ILL");
#if defined __APPLE__
CHECK_STACK_OVERFLOW();
#endif
we could also do this on Linux?
Updated by nobu (Nobuyoshi Nakada) over 3 years ago
Updated by nobu (Nobuyoshi Nakada) over 3 years ago
- Status changed from Open to Closed
Applied in changeset git|574f3af36ea008896419d2e2407f8fce83bdcd2e.
Rewind execution tags more at stack overflow [Bug #18084]
ActionsLike0