Now onigenc_single_byte_code_to_mbclen checks out-of-bound

This commit is contained in:
Nobuyoshi Nakada 2026-01-12 18:39:15 +09:00
parent 76b1d4a481
commit aaf47cca03
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2026-01-12 12:35:28 +00:00

View File

@ -441,7 +441,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
VALUE val = GETARG(); VALUE val = GETARG();
VALUE tmp; VALUE tmp;
unsigned int c; unsigned int c;
int n; int n, encidx;
tmp = rb_check_string_type(val); tmp = rb_check_string_type(val);
if (!NIL_P(tmp)) { if (!NIL_P(tmp)) {
@ -451,11 +451,13 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
goto format_s1; goto format_s1;
} }
n = NUM2INT(val); n = NUM2INT(val);
if (n >= 0) n = rb_enc_codelen((c = n), enc); if (n >= 0) {
n = rb_enc_codelen((c = n), enc);
encidx = rb_ascii8bit_appendable_encoding_index(enc, c);
}
if (n <= 0) { if (n <= 0) {
rb_raise(rb_eArgError, "invalid character"); rb_raise(rb_eArgError, "invalid character");
} }
int encidx = rb_ascii8bit_appendable_encoding_index(enc, c);
if (encidx >= 0 && encidx != rb_enc_to_index(enc)) { if (encidx >= 0 && encidx != rb_enc_to_index(enc)) {
/* special case */ /* special case */
rb_enc_associate_index(result, encidx); rb_enc_associate_index(result, encidx);