Project

General

Profile

Actions

Bug #20883

closed

sprintf with binary strings has incorrect coderange

Added by jhawthorn (John Hawthorn) 16 days ago. Updated 14 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
[ruby-core:119855]

Description

In 9dc6065 we stopped updating the coderange when the encoding became ENCINDEX_ASCII_8BIT. Though ASCII-8BIT (binary) can't ever have a broken coderange, it does need to distinguish between 7bit and valid.

puts ("%s" % "\xe2".b).ascii_only?
# => false from Ruby 2.1 to 3.1
# => true (incorrect) on Ruby 3.2 and 3.3
# => false again on HEAD

This was fixed in master as part of #20189, which clears the coderange in more cases of rb_str_resize which happens to fix this, but we shouldn't rely on it.

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

Actions #1

Updated by jhawthorn (John Hawthorn) 16 days ago

  • Status changed from Open to Closed

Applied in changeset git|1f6dd9071c7994dd639d2e1cf2fe04e944173f17.


Fix update_coderange for binary strings

Although a binary (aka ASCII-8BIT) string will never have a broken
coderange, it still has to differentiate between "valid" and "7bit".

On Ruby 3.4/trunk this problem is masked because we now clear the
coderange more agressively in rb_str_resize, and we happened to always
be strinking this string, but we should not assume that.

On Ruby 3.3 this created strings where ascii_only? was true in cases
it shouldn't be as well as other problems.

Fixes [Bug #20883]

Co-authored-by: Daniel Colson
Co-authored-by: Matthew Draper

Updated by jhawthorn (John Hawthorn) 16 days ago

I opened two backport PRs. I marked 3.2 and 3.3 as REQUIRED for backport, but the bug is fairly mild if the branch maintainers would rather skip it.

3.2: https://github.com/ruby/ruby/pull/12041
3.3: https://github.com/ruby/ruby/pull/12040

Updated by nagachika (Tomoyuki Chikanaga) 14 days ago

  • Backport changed from 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: DONTNEED, 3.2: DONE, 3.3: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) 14 days ago

Merged the PR for ruby_3_2 at 9bcc5c5fd9e8e4d15040eec6850b49d860eba621. Thank you for the PRs.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0