summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-01 15:02:27 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-01 15:02:27 +0900
commitc9423b016cfeab852bc5a829e55e0a11f80b3ab7 (patch)
tree4d1f656f5a2bb2ee6d00b5de44598272ef16b2d8 /test
parent77a073239c207933e8a2562b51a206aa58dc66b4 (diff)
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]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_marshal.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index e269428dda..0565a1c04f 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -779,4 +779,36 @@ 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
+ self.foo.baz = :problem
+ {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
end