[前][次][番号順一覧][スレッド一覧]

ruby-changes:28314

From: nobu <ko1@a...>
Date: Fri, 19 Apr 2013 13:03:59 +0900 (JST)
Subject: [ruby-changes:28314] nobu:r40366 (trunk): marshal.c: no duplicated encoding

nobu	2013-04-19 13:03:29 +0900 (Fri, 19 Apr 2013)

  New Revision: 40366

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40366

  Log:
    marshal.c: no duplicated encoding
    
    * marshal.c (w_object): do not dump encoding which is dumped with
      marshal_dump data.  [ruby-core:54334] [Bug #8276]

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40365)
+++ ChangeLog	(revision 40366)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Apr 19 13:03:14 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (w_object): do not dump encoding which is dumped with
+	  marshal_dump data.  [ruby-core:54334] [Bug #8276]
+
 Fri Apr 19 11:36:53 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (stack_protector): control use of -fstack-protector.
Index: marshal.c
===================================================================
--- marshal.c	(revision 40365)
+++ marshal.c	(revision 40366)
@@ -598,7 +598,8 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L598
     st_table *ivtbl = 0;
     st_data_t num;
     int hasiv = 0;
-#define has_ivars(obj, ivtbl) (((ivtbl) = rb_generic_ivar_table(obj)) != 0 || \
+#define has_ivars_noenc(obj, ivtbl) (((ivtbl) = rb_generic_ivar_table(obj)) != 0)
+#define has_ivars(obj, ivtbl) (has_ivars_noenc(obj, ivtbl) || \
 			       (!SPECIAL_CONST_P(obj) && !ENCODING_IS_ASCII8BIT(obj)))
 
     if (limit == 0) {
@@ -656,7 +657,7 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L657
 
 	    v = rb_funcall2(obj, s_mdump, 0, 0);
 	    check_dump_arg(arg, s_mdump);
-	    hasiv = has_ivars(v, ivtbl);
+	    hasiv = has_ivars_noenc(v, ivtbl);
 	    if (hasiv) w_byte(TYPE_IVAR, arg);
 	    w_class(TYPE_USRMARSHAL, obj, arg, FALSE);
 	    w_object(v, arg, limit);
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 40365)
+++ test/ruby/test_marshal.rb	(revision 40366)
@@ -539,6 +539,24 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L539
     assert_nil(loaded.foo, bug7627)
   end
 
+  class Bug8276
+    attr_reader :data
+    def initialize(data)
+      @data = data
+      freeze
+    end
+    alias marshal_dump data
+    alias marshal_load initialize
+  end
+
+  def test_marshal_dump_excess_encoding
+    bug8276 = '[ruby-core:54334] [Bug #8276]'
+    t = Bug8276.new(bug8276)
+    s = Marshal.dump(t)
+    assert_nothing_raised(RuntimeError) {s = Marshal.load(s)}
+    assert_equal(t.data, s.data, bug8276)
+  end
+
   def test_class_ivar
     assert_raise(TypeError) {Marshal.load("\x04\x08Ic\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}
     assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]