Bug #20595
closedCorruption of encoding name string
Description
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:
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"]
Updated by peterzhu2118 (Peter Zhu) 6 months ago
The Ruby 3.3 backport PR is here: https://github.com/ruby/ruby/pull/11063
Updated by peterzhu2118 (Peter Zhu) 6 months ago
- Status changed from Open to Closed
Applied in changeset git|c6a0d03649c686a537c1f513a1e32205ac6a6512.
Fix corruption of encoding name string
[Bug #20595]
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:
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"]
Co-authored-by: Matthew Valentine-House matt@eightbitraptor.com
Updated by k0kubun (Takashi Kokubun) 6 months ago
- 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 291cc913503475a204c93a53a2f470c8cc6bfca2.