From: "ioquatix (Samuel Williams)" Date: 2021-08-18T04:20:37+00:00 Subject: [ruby-core:104965] [Ruby master Bug#18084] `JSON.dump` can crash VM. Issue #18084 has been updated by ioquatix (Samuel Williams). @nobu suggested the following code could be updated: ~~~ clang sigill(int sig SIGINFO_ARG) { check_reserved_signal("ILL"); #if defined __APPLE__ CHECK_STACK_OVERFLOW(); #endif ~~~ we could also do this on Linux? ---------------------------------------- Bug #18084: `JSON.dump` can crash VM. https://bugs.ruby-lang.org/issues/18084#change-93329 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- ~~~ ruby 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 `
' 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 `
' 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 `
' 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 `
' 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 `
' 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? -- https://bugs.ruby-lang.org/ Unsubscribe: