merge revision(s) ade56737e2273847426214035c0ff2340b43799a: [Backport #20190] (#10300)

Fix coderange of invalid_encoding_string.<<(ord)

	Appending valid encoding character can change coderange from invalid to valid.
	Example: "\x95".force_encoding('sjis')<<0x5C will be a valid string "\x{955C}"
This commit is contained in:
NARUSE, Yui 2024-03-20 22:40:46 +09:00 committed by GitHub
parent 69cee6fee5
commit ce372be903
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -3522,8 +3522,12 @@ rb_str_concat(VALUE str1, VALUE str2)
}
rb_str_resize(str1, pos+len);
memcpy(RSTRING_PTR(str1) + pos, buf, len);
if (cr == ENC_CODERANGE_7BIT && code > 127)
if (cr == ENC_CODERANGE_7BIT && code > 127) {
cr = ENC_CODERANGE_VALID;
}
else if (cr == ENC_CODERANGE_BROKEN) {
cr = ENC_CODERANGE_UNKNOWN;
}
ENC_CODERANGE_SET(str1, cr);
}
return str1;

View File

@ -301,6 +301,9 @@ CODE
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << -1}
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << 0x81308130}
assert_nothing_raised {S("a".force_encoding(Encoding::GB18030)) << 0x81308130}
s = "\x95".force_encoding(Encoding::SJIS).tap(&:valid_encoding?)
assert_predicate(s << 0x5c, :valid_encoding?)
end
def test_MATCH # '=~'

View File

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 15
#define RUBY_PATCHLEVEL 16
#include "ruby/version.h"
#include "ruby/internal/abi.h"