mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Prohibit invalid encoding symbols [Bug #18184]
This commit is contained in:
parent
7cec727612
commit
49af9012a2
2 changed files with 14 additions and 4 deletions
|
@ -1479,7 +1479,13 @@ r_symreal(struct load_arg *arg, int ivar)
|
||||||
idx = sym2encidx(sym, r_object(arg));
|
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;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -814,9 +814,13 @@ class TestMarshal < Test::Unit::TestCase
|
||||||
assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
|
assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
|
||||||
ruby2_keywords_test(*[hash2])
|
ruby2_keywords_test(*[hash2])
|
||||||
}
|
}
|
||||||
hash2 = Marshal.load(data.sub(/:\x06K(?=T\z)/, "I\\&\x06:\x0dencoding\"\x0dUTF-16LE"))
|
end
|
||||||
assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
|
|
||||||
ruby2_keywords_test(*[hash2])
|
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue