From 78ee2c245331e353e218b8fac9ca722a2bcd8fea Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 1 Jul 2019 16:20:03 +0900 Subject: 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] --- test/ruby/test_marshal.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test/ruby/test_marshal.rb') diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index 0565a1c04f..f6d84d181a 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -795,7 +795,11 @@ class TestMarshal < Test::Unit::TestCase end def marshal_dump - self.foo.baz = :problem + if self.foo.baz + self.foo.remove_instance_variable(:@baz) + else + self.foo.baz = :problem + end {foo: self.foo} end @@ -811,4 +815,12 @@ class TestMarshal < Test::Unit::TestCase 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 -- cgit v1.2.3