ruby-changes:68080
From: Nobuyoshi <ko1@a...>
Date: Thu, 23 Sep 2021 01:20:03 +0900 (JST)
Subject: [ruby-changes:68080] 552728a23a (master): Check the encoding of `ruby2_keywords_flag` [Bug #18184]
https://git.ruby-lang.org/ruby.git/commit/?id=552728a23a From 552728a23aeab0df598b356b19a573259e297d14 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 23 Sep 2021 00:04:14 +0900 Subject: 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(-) diff --git a/marshal.c b/marshal.c index 47b13bc..ab0e63c 100644 --- a/marshal.c +++ b/marshal.c @@ -1422,6 +1422,7 @@ ruby2_keywords_flag_check(VALUE sym) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1422 { 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, l)) { diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index 619aaa6..9eea3c2 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -810,7 +810,11 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L810 hash = Marshal.load(data) assert_equal(42, ruby2_keywords_test(*[hash])) - hash2 = Marshal.load(data.sub!(/\x06K(?=T\z)/, "\x08KEY")) + hash2 = Marshal.load(data.sub(/\x06K(?=T\z)/, "\x08KEY")) + assert_raise(ArgumentError, /\(given 1, expected 0\)/) { + ruby2_keywords_test(*[hash2]) + } + hash2 = Marshal.load(data.sub(/:\x06K(?=T\z)/, "I\\&\x06:\x0dencoding\"\x0dUTF-16LE")) assert_raise(ArgumentError, /\(given 1, expected 0\)/) { ruby2_keywords_test(*[hash2]) } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/