1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 7c0230b05d0978958f89434c84ddd9c82419c1a5,552728a23aeab0df598b356b19a573259e297d14,49af9012a20a824542cf588e55e5488895553e09: [Backport #18184]

Check the entire name as `ruby2_keywords_flag` [Bug #18184]

	---
	 marshal.c                 | 2 +-
	 test/ruby/test_marshal.rb | 8 +++++++-
	 2 files changed, 8 insertions(+), 2 deletions(-)

	Check the encoding of `ruby2_keywords_flag` [Bug #18184]

	---
	 marshal.c                 | 1 +
	 test/ruby/test_marshal.rb | 6 +++++-
	 2 files changed, 6 insertions(+), 1 deletion(-)

	Prohibit invalid encoding symbols [Bug #18184]

	---
	 marshal.c                 |  8 +++++++-
	 test/ruby/test_marshal.rb | 10 +++++++---
	 2 files changed, 14 insertions(+), 4 deletions(-)
This commit is contained in:
nagachika 2021-10-03 16:16:18 +09:00
parent 5341eca588
commit f192e01233
3 changed files with 25 additions and 4 deletions

View file

@ -1424,9 +1424,10 @@ ruby2_keywords_flag_check(VALUE sym)
{
const char *p;
long l;
if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return 0;
RSTRING_GETMEM(sym, p, l);
if (l <= 0) return 0;
if (name_equal(name_s_ruby2_keywords_flag, rb_strlen_lit(name_s_ruby2_keywords_flag), p, 1)) {
if (name_equal(name_s_ruby2_keywords_flag, rb_strlen_lit(name_s_ruby2_keywords_flag), p, l)) {
return 1;
}
return 0;
@ -1461,7 +1462,13 @@ r_symreal(struct load_arg *arg, int ivar)
idx = sym2encidx(sym, r_object(arg));
}
}
if (idx > 0) rb_enc_associate_index(s, idx);
if (idx > 0) {
rb_enc_associate_index(s, idx);
if (rb_enc_str_coderange(s) == ENC_CODERANGE_BROKEN) {
rb_raise(rb_eArgError, "invalid byte sequence in %s: %+"PRIsVALUE,
rb_enc_name(rb_enc_from_index(idx)), s);
}
}
return s;
}

View file

@ -785,8 +785,22 @@ class TestMarshal < Test::Unit::TestCase
def test_marshal_with_ruby2_keywords_hash
flagged_hash = ruby2_keywords_hash(key: 42)
hash = Marshal.load(Marshal.dump(flagged_hash))
data = Marshal.dump(flagged_hash)
hash = Marshal.load(data)
assert_equal(42, ruby2_keywords_test(*[hash]))
hash2 = Marshal.load(data.sub(/\x06K(?=T\z)/, "\x08KEY"))
assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
ruby2_keywords_test(*[hash2])
}
end
def test_invalid_byte_sequence_symbol
data = Marshal.dump(:K)
data = data.sub(/:\x06K/, "I\\&\x06:\x0dencoding\"\x0dUTF-16LE")
assert_raise(ArgumentError, /UTF-16LE: "\\x4B"/) {
Marshal.load(data)
}
end
def exception_test

View file

@ -12,7 +12,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 139
#define RUBY_PATCHLEVEL 140
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 10