[ruby-core:118391] [Ruby master Bug#20595] Corruption of encoding name string

Issue #20595 has been reported by peterzhu2118 (Peter Zhu). ---------------------------------------- Bug #20595: Corruption of encoding name string https://bugs.ruby-lang.org/issues/20595 * Author: peterzhu2118 (Peter Zhu) * Status: Open * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED ---------------------------------------- GitHub PR: https://github.com/ruby/ruby/pull/11062 enc_set_default_encoding will free the C string if the encoding is nil, but the C string can be used by the encoding name string. This will cause the encoding name string to be corrupted. Consider the following code: ```ruby Encoding.default_internal = Encoding::ASCII_8BIT names = Encoding.default_internal.names p names Encoding.default_internal = nil p names ``` It outputs: ``` ["ASCII-8BIT", "BINARY", "internal"] ["ASCII-8BIT", "BINARY", "\x00\x00\x00\x00\x00\x00\x00\x00"] ``` -- https://bugs.ruby-lang.org/

Issue #20595 has been updated by peterzhu2118 (Peter Zhu). The Ruby 3.3 backport PR is here: https://github.com/ruby/ruby/pull/11063 ---------------------------------------- Bug #20595: Corruption of encoding name string https://bugs.ruby-lang.org/issues/20595#change-108907 * Author: peterzhu2118 (Peter Zhu) * Status: Open * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED ---------------------------------------- GitHub PR: https://github.com/ruby/ruby/pull/11062 enc_set_default_encoding will free the C string if the encoding is nil, but the C string can be used by the encoding name string. This will cause the encoding name string to be corrupted. Consider the following code: ```ruby Encoding.default_internal = Encoding::ASCII_8BIT names = Encoding.default_internal.names p names Encoding.default_internal = nil p names ``` It outputs: ``` ["ASCII-8BIT", "BINARY", "internal"] ["ASCII-8BIT", "BINARY", "\x00\x00\x00\x00\x00\x00\x00\x00"] ``` -- https://bugs.ruby-lang.org/

Issue #20595 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE ruby_3_3 commit:291cc913503475a204c93a53a2f470c8cc6bfca2. ---------------------------------------- Bug #20595: Corruption of encoding name string https://bugs.ruby-lang.org/issues/20595#change-109024 * Author: peterzhu2118 (Peter Zhu) * Status: Closed * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE ---------------------------------------- GitHub PR: https://github.com/ruby/ruby/pull/11062 enc_set_default_encoding will free the C string if the encoding is nil, but the C string can be used by the encoding name string. This will cause the encoding name string to be corrupted. Consider the following code: ```ruby Encoding.default_internal = Encoding::ASCII_8BIT names = Encoding.default_internal.names p names Encoding.default_internal = nil p names ``` It outputs: ``` ["ASCII-8BIT", "BINARY", "internal"] ["ASCII-8BIT", "BINARY", "\x00\x00\x00\x00\x00\x00\x00\x00"] ``` -- https://bugs.ruby-lang.org/
participants (2)
-
k0kubun (Takashi Kokubun)
-
peterzhu2118 (Peter Zhu)