Skip to content

ArgumentError: negative string size (or size too big) for rb_enc_left_char_head() #3267

@eregon

Description

@eregon

Found by @segiddins and reported on the Bundler Slack:

rb_enc_left_char_head has length = start - end which will always be negative, and results in an exception in the call to rb_str_new for passing a negative length, and it probably should be length = end - start

And indeed adding a C API spec for it I can confirm:

C-API Encoding function rb_enc_left_char_head returns the head position of a character ERROR
ArgumentError: negative string size (or size too big)
/home/eregon/code/truffleruby-ws/graal/sdk/mxbuild/linux-amd64/GRAALVM_3555B82685_JAVA21/graalvm-3555b82685-java21-24.0.0-dev/languages/ruby/lib/truffle/truffle/cext.rb:1138:in `rb_exc_raise'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/c/cext/exception.c:29:in `rb_exc_raise'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/c/cext/string.c:52:in `rb_str_new'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/c/cext/encoding.c:232:in `rb_enc_left_char_head'
encoding_spec.c:312:in `encoding_spec_rb_enc_left_char_head'
/home/eregon/code/truffleruby-ws/graal/sdk/mxbuild/linux-amd64/GRAALVM_3555B82685_JAVA21/graalvm-3555b82685-java21-24.0.0-dev/languages/ruby/lib/truffle/truffle/cext_ruby.rb:42:in `rb_enc_left_char_head'
/home/eregon/code/truffleruby-ws/truffleruby/spec/ruby/optional/capi/encoding_spec.rb:679:in `block (3 levels) in <top (required)>'
/home/eregon/code/truffleruby-ws/truffleruby/spec/ruby/optional/capi/encoding_spec.rb:42:in `<top (required)>'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions