Bug #22451
closedCoderange may be set incorrectly when concatenating a string into itself
Description
s = "\x81\x30".force_encoding("GB18030")
#=> "\x810"
s.valid_encoding? # This is invalid
#=> false
(s + s).valid_encoding? # However it becomes valid when repeated
#=> true
(s << s).valid_encoding? # But concat assumed the coderange would not change
#=> false
s.b.force_encoding(s.encoding).valid_encoding? # Same bytes, different answer
#=> true
Updated by byroot (Jean Boussier) about 1 month ago
- Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: WONTFIX, 3.4: REQUIRED, 4.0: REQUIRED
Seems to have been present all the way since 1.9.
Updated by jhawthorn (John Hawthorn) 20 days ago
- Status changed from Open to Closed
Applied in changeset git|b740f7d553e6ee4abdff8847760394b4e6ea389c.
Don't write str2's code range back in rb_str_buf_append
Since rb_enc_str_coderange(str2) is called first, str2_cr is never
UNKNOWN and rb_enc_cr_str_buf_cat returns it unchanged, so writing it
back to str2 is redundant. It is also an unsynchronized write to str2,
which may be a frozen string shared with other Ractors.
When str and str2 are the same string, the write-back also overwrote
the result's code range with the pre-append one, so s << s could
leave a valid string marked BROKEN.
[Bug #22451]
Updated by nagachika (Tomoyuki Chikanaga) 13 days ago
- Backport changed from 3.3: WONTFIX, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: WONTFIX, 3.4: DONE, 4.0: REQUIRED
Merged into ruby_3_4 at https://github.com/ruby/ruby/commit/98ba0a86a3b15a94d24ef1c281cd1b48f73c793e
Updated by tenderlovemaking (Aaron Patterson) 7 days ago
- Backport changed from 3.3: WONTFIX, 3.4: DONE, 4.0: REQUIRED to 3.3: WONTFIX, 3.4: DONE, 4.0: DONE
ruby_4_0 ccb92217d3 merged revision(s) b740f7d553.