summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-12-15 07:14:45 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-12-15 07:14:45 +0000
commitec2934d5048d8f3f0bff32eeddf9f244fa407397 (patch)
tree09c81d069c878f9f3e0111a02c4672eee1a625d9 /test
parent00f4c13e22967de1d7e42085b2fc32bf6718f580 (diff)
merge revision(s) c9423b016cfeab852bc5a829e55e0a11f80b3ab7,0b1e26398e018116180bf41cb63887f77d5d1b82,78ee2c245331e353e218b8fac9ca722a2bcd8fea: [Backport #15968]
marshal.c: check instance variable count * marshal.c (w_obj_each): ensure that no instance variable was added while dumping other instance variables. [Bug #15968] Hoisted out w_ivar_each marshal.c: check instance variable count * marshal.c (w_ivar_each): ensure that no instance variable was removed while dumping other instance variables. [Bug #15968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_marshal.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index e269428dda..f6d84d181a 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -779,4 +779,48 @@ class TestMarshal < Test::Unit::TestCase
obj = Bug14314.new(foo: 42)
assert_equal obj, Marshal.load(Marshal.dump(obj))
end
+
+ class Bug15968
+ attr_accessor :bar, :baz
+
+ def initialize
+ self.bar = Bar.new(self)
+ end
+
+ class Bar
+ attr_accessor :foo
+
+ def initialize(foo)
+ self.foo = foo
+ end
+
+ def marshal_dump
+ if self.foo.baz
+ self.foo.remove_instance_variable(:@baz)
+ else
+ self.foo.baz = :problem
+ end
+ {foo: self.foo}
+ end
+
+ def marshal_load(data)
+ self.foo = data[:foo]
+ end
+ end
+ end
+
+ def test_marshal_dump_adding_instance_variable
+ obj = Bug15968.new
+ assert_raise_with_message(RuntimeError, /instance variable added/) do
+ Marshal.dump(obj)
+ end
+ end
+
+ def test_marshal_dump_removing_instance_variable
+ obj = Bug15968.new
+ obj.baz = :Bug15968
+ assert_raise_with_message(RuntimeError, /instance variable removed/) do
+ Marshal.dump(obj)
+ end
+ end
end