Project

General

Profile

Actions

Bug #20189

open

`rb_str_resize` does not clear coderange when expanding

Added by tompng (tomoya ishida) 10 months ago. Updated 10 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-01-09T07:07:19Z master db476cc71c) [x86_64-linux]
[ruby-core:116226]

Description

Expanding string in some encoding (utf16 utf32) can change coderange to either valid or broken, but rb_str_resize does not clear coderange.

This will cause a bug in c-extension libraries that use rb_str_resize.

# Example for stringio
s = StringIO.new("\0".encode('UTF-16LE'))

s.truncate(1); s.truncate(2); s.string.valid_encoding?
#=> true
s.truncate(1); s.string.valid_encoding?; s.truncate(2); s.string.valid_encoding?
#=> false (expect to be true)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0