From aa0fad51482c24ece58ec7186c45fd340b35ecb1 Mon Sep 17 00:00:00 2001 From: Olek Janiszewski Date: Fri, 11 Mar 2016 10:20:41 +0100 Subject: Prevent `Marshal.load` from looping infinitely Fix a bug in `Marshal.load` that caused it to loop indefinitely when trying to autoload a constant that resolved to a different name. This could occur when marshalling an ActiveRecord 4.0 object (e.g. into memcached) and then trying to unmarshal it with Rails 4.2. The marshalled payload contains a reference to `ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column`, which in Rails 4.2 resolves to `ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column`. --- activesupport/test/core_ext/marshal_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/test/core_ext/marshal_test.rb') diff --git a/activesupport/test/core_ext/marshal_test.rb b/activesupport/test/core_ext/marshal_test.rb index 5427837d19..07c0c0d8cb 100644 --- a/activesupport/test/core_ext/marshal_test.rb +++ b/activesupport/test/core_ext/marshal_test.rb @@ -64,6 +64,17 @@ class MarshalTest < ActiveSupport::TestCase end end + test "when one constant resolves to another" do + class Parent; C = Class.new; end + class Child < Parent; C = Class.new; end + + dump = Marshal.dump(Child::C.new) + + Child.send(:remove_const, :C) + + assert_raise(ArgumentError) { Marshal.load(dump) } + end + test "that a real missing class is causing an exception" do dumped = nil with_autoloading_fixtures do -- cgit v1.2.3