ruby-changes:44630
From: nobu <ko1@a...>
Date: Fri, 11 Nov 2016 20:52:10 +0900 (JST)
Subject: [ruby-changes:44630] nobu:r56703 (trunk): range.c: check loading
nobu 2016-11-11 20:52:03 +0900 (Fri, 11 Nov 2016) New Revision: 56703 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56703 Log: range.c: check loading * range.c (range_loader): check loading values if the data came from an initialized range object. [ruby-core:78067] [Bug #12915] Modified files: trunk/range.c trunk/test/ruby/test_range.rb Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 56702) +++ test/ruby/test_range.rb (revision 56703) @@ -110,6 +110,16 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L110 assert_nothing_raised { r.instance_eval { initialize 5, 6} } end + def test_marshal + r = 1..2 + assert_equal(r, Marshal.load(Marshal.dump(r))) + r = 1...2 + assert_equal(r, Marshal.load(Marshal.dump(r))) + s = Marshal.dump(r) + s.sub!(/endi./n, 'end0') + assert_raise(ArgumentError) {Marshal.load(s)} + end + def test_bad_value assert_raise(ArgumentError) { (1 .. :a) } end Index: range.c =================================================================== --- range.c (revision 56702) +++ range.c (revision 56703) @@ -1231,14 +1231,19 @@ range_dumper(VALUE range) https://github.com/ruby/ruby/blob/trunk/range.c#L1231 static VALUE range_loader(VALUE range, VALUE obj) { + VALUE beg, end, excl; + if (!RB_TYPE_P(obj, T_OBJECT) || RBASIC(obj)->klass != rb_cObject) { rb_raise(rb_eTypeError, "not a dumped range object"); } range_modify(range); - RANGE_SET_BEG(range, rb_ivar_get(obj, id_beg)); - RANGE_SET_END(range, rb_ivar_get(obj, id_end)); - RANGE_SET_EXCL(range, rb_ivar_get(obj, id_excl)); + beg = rb_ivar_get(obj, id_beg); + end = rb_ivar_get(obj, id_end); + excl = rb_ivar_get(obj, id_excl); + if (!NIL_P(excl)) { + range_init(range, beg, end, RBOOL(RTEST(excl))); + } return range; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/