Project

General

Profile

Actions

Bug #22451

closed

Coderange may be set incorrectly when concatenating a string into itself

Bug #22451: Coderange may be set incorrectly when concatenating a string into itself

Added by jhawthorn (John Hawthorn) about 1 month ago. Updated 7 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127151]

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

https://github.com/ruby/ruby/pull/19357

Updated by byroot (Jean Boussier) about 1 month ago 1Actions #1 [ruby-core:127156]

  • 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 Actions #2

  • 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 Actions #3 [ruby-core:127348]

  • Backport changed from 3.3: WONTFIX, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: WONTFIX, 3.4: DONE, 4.0: REQUIRED

Updated by tenderlovemaking (Aaron Patterson) 7 days ago Actions #4 [ruby-core:127422]

  • 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.

Actions

Also available in: PDF Atom