Project

General

Profile

Actions

Bug #22547

closed

`String.new("", encoding: Encoding::CESU_8)` fails the STR_EMBEDDABLE_P assertion “too big termlen: 6” on debug builds

Bug #22547: `String.new("", encoding: Encoding::CESU_8)` fails the STR_EMBEDDABLE_P assertion “too big termlen: 6” on debug builds

Added by yahonda (Yasuo Honda) 9 days ago. Updated 8 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-11-13T22:58:20Z HEAD 346d1f63b7) +PRISM [x86_64-linux]
[ruby-core:127476]

Description

The Rails nightly CI against Ruby master (debug build) started aborting in Active Support with Assertion Failed: STR_EMBEDDABLE_P:termlen <= 4: too big termlen: 6. It bisects to 346d1f63b7 ("Ignore negative capacity", https://github.com/ruby/ruby/pull/19887).

https://buildkite.com/rails/rails-nightly/builds/4922#01a1d6b6-024b-49f3-95b6-6afe9c6328e8/L2134

The full log of that Active Support job is attached (rails-nightly_build_4922_activesupport-master-debug.log.zip).

It can be reproduced with a single Active Support test:

cd activesupport && bin/test test/transliterate_test.rb -n test_transliterate_handles_strings_with_incompatible_encodings

Steps to reproduce

Build Ruby with cppflags=-DRUBY_DEBUG=1, then:

s = String.new("", encoding: Encoding::CESU_8)
puts "OK #{s.encoding}"

Expected behavior

$ ruby -v
ruby 4.1.0dev (2026-11-13T22:47:35Z HEAD 293c4f9246) +PRISM [x86_64-linux]
$ ruby rep.rb
OK CESU-8

Actual behavior

$ ruby -v
ruby 4.1.0dev (2026-11-13T22:58:20Z HEAD 346d1f63b7) +PRISM [x86_64-linux]
$ ruby rep.rb
string.c:281: Assertion Failed: STR_EMBEDDABLE_P:termlen <= 4: too big termlen: 6
ruby 4.1.0dev (2026-11-13T22:58:20Z HEAD 346d1f63b7) +PRISM [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0002 p:0016 s:0011 E:002280 l:n b:---- r:(nil) EVAL   rep.rb:1 [FINISH]
c:0001 p:0000 s:0003 E:000f38 l:y b:---- r:(nil) DUMMY  [FINISH]

Files

Updated by yahonda (Yasuo Honda) 9 days ago Actions #1 [ruby-core:127477]

346d1f63b7 only added the assertion. To find where the terminator length of 6 comes from, I added the same check to STR_EMBEDDABLE_P by hand and built the two commits around 14285dee21 ("Optimize String.new(capacity:)", https://github.com/ruby/ruby/pull/19674) with cppflags=-DRUBY_DEBUG=1:

RUBY_ASSERT(termlen <= 4, "too big termlen: %ld", (long)termlen);
Commit Result of String.new("", encoding: Encoding::CESU_8)
af71c7aeb7 (parent of 14285dee21) OK CESU-8
14285dee21 Assertion Failed: STR_EMBEDDABLE_P:termlen <= 4: too big termlen: 6

rb_str_alloc_enc_capa, added by 14285dee21, takes the terminator length from rb_enc_mbmaxlen(enc), and CESU-8 has a max byte length of 6.

Updated by nobu (Nobuyoshi Nakada) 8 days ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|98c72aae69408150820bf91b1dff07ab2b026e68.


[Bug #22547] Remove the unnecessary assertion

Actions

Also available in: PDF Atom