зеркало из https://github.com/github/ruby.git
marshal.c: register symbol strings first
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
74768415d8
Коммит
ffcb7abe0b
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
Mon Mar 23 02:03:28 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
||||
Mon Mar 23 01:44:35 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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 Mar 22 22:07:40 2015 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* doc/etc.rd.ja: Fix wrong coding for Emacs.
|
||||
|
|
31
marshal.c
31
marshal.c
|
@ -1295,11 +1295,18 @@ r_bytes0(long len, struct load_arg *arg)
|
|||
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 */
|
||||
|
@ -1327,7 +1334,8 @@ r_symreal(struct load_arg *arg, int ivar)
|
|||
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) {
|
||||
|
@ -1336,10 +1344,8 @@ r_symreal(struct load_arg *arg, int ivar)
|
|||
}
|
||||
}
|
||||
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
|
||||
|
@ -1367,7 +1373,7 @@ r_symbol(struct load_arg *arg)
|
|||
static VALUE
|
||||
r_unique(struct load_arg *arg)
|
||||
{
|
||||
return rb_sym2str(r_symbol(arg));
|
||||
return r_symbol(arg);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -1465,7 +1471,7 @@ r_ivar(VALUE obj, int *has_encoding, struct load_arg *arg)
|
|||
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);
|
||||
}
|
||||
|
@ -1790,13 +1796,13 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
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;
|
||||
|
@ -1934,11 +1940,12 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
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:
|
||||
|
|
|
@ -252,6 +252,17 @@ class TestMarshal < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче