Prohibit invalid encoding symbols [Bug #18184]

This commit is contained in:
Nobuyoshi Nakada 2021-09-23 16:02:44 +09:00
parent 7cec727612
commit 49af9012a2
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 14 additions and 4 deletions

View file

@ -1479,7 +1479,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;
}