ohler55 / oj

Optimized JSON
http://www.ohler.com/oj
MIT License
3.16k stars 252 forks source link

Fix SEGV in JSON.generate if to_json method returns invalid object #847

Closed Watson1978 closed 1 year ago

Watson1978 commented 1 year ago

This patch will raise TypeError exception in JSON.generate if to_json method returns invalid object to avoid SEGV

Test code

require 'oj'
Oj.mimic_JSON

class Foo
  def to_json
    nil
  end
end

obj = { foo: Foo.new }
puts JSON.generate(obj)

Similar: https://github.com/ohler55/oj/pull/836