ruby-changes:38551
From: nagachika <ko1@a...>
Date: Sun, 24 May 2015 04:19:23 +0900 (JST)
Subject: [ruby-changes:38551] nagachika:r50632 (ruby_2_2): merge revision(s) 50057, 50065: [Backport #10991]
nagachika 2015-05-24 04:18:57 +0900 (Sun, 24 May 2015) New Revision: 50632 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50632 Log: merge revision(s) 50057,50065: [Backport #10991] * marshal.c (r_symreal): register symbol names as strings first so that r_symlink always returns valid names. [ruby-core:68587] [Bug #10991] * marshal.c (r_ivar, r_object0): now need to intern symbol names. * marshal.c (r_object0): compare with symbol names. Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/marshal.c branches/ruby_2_2/test/ruby/test_marshal.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 50631) +++ ruby_2_2/ChangeLog (revision 50632) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Sun May 24 03:56:27 2015 Nobuyoshi Nakada <nobu@r...> + + * marshal.c (r_symreal): register symbol names as strings first so + that r_symlink always returns valid names. + [ruby-core:68587] [Bug #10991] + + * marshal.c (r_ivar, r_object0): now need to intern symbol names. + + * marshal.c (r_object0): compare with symbol names. + Sun May 24 03:53:07 2015 Eric Wong <e@8...> * ext/socket/ancdata.c (bsock_recvmsg_internal): GC guard Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 50631) +++ ruby_2_2/version.h (revision 50632) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.3" #define RUBY_RELEASE_DATE "2015-05-24" -#define RUBY_PATCHLEVEL 128 +#define RUBY_PATCHLEVEL 129 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 5 Index: ruby_2_2/marshal.c =================================================================== --- ruby_2_2/marshal.c (revision 50631) +++ ruby_2_2/marshal.c (revision 50632) @@ -1298,11 +1298,18 @@ r_bytes0(long len, struct load_arg *arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1298 static int sym2encidx(VALUE sym, VALUE val) { - if (sym == ID2SYM(rb_id_encoding())) { + static const char name_encoding[8] = "encoding"; + const char *p; + long l; + if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return -1; + RSTRING_GETMEM(sym, p, l); + if (l <= 0) return -1; + if (l == sizeof(name_encoding) && + memcmp(p, name_encoding, sizeof(name_encoding)) == 0) { int idx = rb_enc_find_index(StringValueCStr(val)); return idx; } - else if (sym == ID2SYM(rb_intern("E"))) { + else if (l == 1 && *p == 'E') { if (val == Qfalse) return rb_usascii_encindex(); else if (val == Qtrue) return rb_utf8_encindex(); /* bogus ignore */ @@ -1330,7 +1337,8 @@ r_symreal(struct load_arg *arg, int ivar https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1337 int idx = -1; st_index_t n = arg->symbols->num_entries; - st_insert(arg->symbols, (st_data_t)n, (st_data_t)0); + if (rb_enc_str_asciionly_p(s)) rb_enc_associate_index(s, ENCINDEX_US_ASCII); + st_insert(arg->symbols, (st_data_t)n, (st_data_t)s); if (ivar) { long num = r_long(arg); while (num-- > 0) { @@ -1339,10 +1347,8 @@ r_symreal(struct load_arg *arg, int ivar https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1347 } } if (idx > 0) rb_enc_associate_index(s, idx); - sym = rb_str_intern(s); - st_insert(arg->symbols, (st_data_t)n, (st_data_t)sym); - return sym; + return s; } static VALUE @@ -1370,7 +1376,7 @@ r_symbol(struct load_arg *arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1376 static VALUE r_unique(struct load_arg *arg) { - return rb_sym2str(r_symbol(arg)); + return r_symbol(arg); } static VALUE @@ -1468,7 +1474,7 @@ r_ivar(VALUE obj, int *has_encoding, str https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1474 if (has_encoding) *has_encoding = TRUE; } else { - rb_ivar_set(obj, SYM2ID(sym), val); + rb_ivar_set(obj, rb_intern_str(sym), val); } } while (--len > 0); } @@ -1793,13 +1799,13 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1799 v = r_entry0(v, idx, arg); values = rb_ary_new2(len); for (i=0; i<len; i++) { + VALUE n = rb_sym2str(RARRAY_AREF(mem, i)); slot = r_symbol(arg); - if (RARRAY_AREF(mem, i) != slot) { + if (!rb_str_equal(n, slot)) { rb_raise(rb_eTypeError, "struct %"PRIsVALUE" not compatible (:%"PRIsVALUE" for :%"PRIsVALUE")", rb_class_name(klass), - rb_sym2str(slot), - rb_sym2str(RARRAY_AREF(mem, i))); + slot, n); } rb_ary_push(values, r_object(arg)); arg->readable -= 2; @@ -1937,11 +1943,12 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1943 else { v = r_symreal(arg, 0); } + v = rb_str_intern(v); v = r_leave(v, arg); break; case TYPE_SYMLINK: - v = r_symlink(arg); + v = rb_str_intern(r_symlink(arg)); break; default: Index: ruby_2_2/test/ruby/test_marshal.rb =================================================================== --- ruby_2_2/test/ruby/test_marshal.rb (revision 50631) +++ ruby_2_2/test/ruby/test_marshal.rb (revision 50632) @@ -252,6 +252,17 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_marshal.rb#L252 assert_include(Marshal.dump([:a, :a]), ';') end + def test_symlink_in_ivar + bug10991 = '[ruby-core:68587] [Bug #10991]' + sym = Marshal.load("\x04\x08" + + "I" ":\x0bKernel" + + ("\x06" + + ("I" ":\x07@a" + + ("\x06" ":\x07@b" "e;\x0""o:\x0bObject""\x0")) + + "0")) + assert_equal(:Kernel, sym, bug10991) + end + ClassUTF8 = eval("class R\u{e9}sum\u{e9}; self; end") iso_8859_1 = Encoding::ISO_8859_1 Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r50057,50065 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/