Project

General

Profile

Actions

Bug #20595

closed

Corruption of encoding name string

Added by peterzhu2118 (Peter Zhu) 4 days ago. Updated 3 days ago.

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

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"]
Actions #2

Updated by peterzhu2118 (Peter Zhu) 3 days 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

Actions

Also available in: Atom PDF

Like0
Like0Like0