Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug #20322] Fix rb_enc_interned_str_cstr null encoding #10169

Merged
merged 3 commits into from
Mar 3, 2024

Conversation

thomasmarshall
Copy link
Contributor

https://bugs.ruby-lang.org/issues/20322

While adding support for rb_enc_interned_str_cstr in TruffleRuby, we noticed the documentation says that enc can be a null pointer:

* @note `enc` can be a null pointer.

However, this currently causes a segmentation fault when it tries to autoload the encoding because it calls rb_enc_mbmaxlen which expects a non-null encoding. This commit fixes the issue by checking for NULL before calling rb_enc_autoload.

I'm not sure how necessary the fix is, perhaps nobody has encountered this issue. Alternatively we could just remove the note about null pointers from the docs.

The documentation for `rb_enc_interned_str_cstr` notes that `enc` can be
a null pointer, but this currently causes a segmentation fault when
trying to autoload the encoding. This commit fixes the issue by checking
for NULL before calling `rb_enc_autoload`.
Copy link

launchable-app bot commented Mar 2, 2024

Launchable Report

❌ Test session #2679418 failedos:macos-arm-oss test_opts:--repeat-count:2 test_task:test-all
🔔 no issues ✖️1 test failed ✔️49558 tests passed

❌ Test session #2679429 failedos:ubuntu-20.04 test_opts:cppflags:-DVM_CHECK_MODE test_task:check
🔔 no issues ✖️1 test failed ✔️24806 tests passed

Passed test sessions

✅ Test session #2679416 passed os:macos-arm-oss test_opts: test_task:check
✅ Test session #2679422 passed os:ubuntu-20.04 test_opts:--disable-yjit test_task:check
✅ Test session #2679424 passed os:ubuntu-20.04 test_opts:--enable-shared--enable-load-relative test_task:check
✅ Test session #2679430 passed os:macos-13 test_opts: test_task:check
✅ Test session #2679431 passed os:ubuntu-20.04 test_opts: test_task:check
✅ Test session #2679441 passed os:macos-12 test_opts: test_task:check

Build: refs_pull_10169_merge_039a1129ab55b887a1721baecb366998f4d05c69

spec/ruby/optional/capi/string_spec.rb Outdated Show resolved Hide resolved
thomasmarshall and others added 2 commits March 3, 2024 08:53
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
@nobu nobu enabled auto-merge (squash) March 3, 2024 10:17
@nobu nobu merged commit 7e4b1f8 into ruby:master Mar 3, 2024
100 checks passed
thomasmarshall added a commit to Shopify/truffleruby that referenced this pull request Mar 5, 2024
This commit adds support for a null pointer to be passed as the encoding
argument to rb_enc_interned_str_cstr.

When we implemented this function originally, we noticed that the CRuby
behavior did not match the header documentation, so we opted not to
support it. However, this has now been fixed in CRuby [1], so we can fix
it here as well.

[1]: ruby/ruby#10169
thomasmarshall added a commit to Shopify/truffleruby that referenced this pull request Mar 5, 2024
This commit adds support for a null pointer to be passed as the encoding
argument to rb_enc_interned_str_cstr.

When we implemented this function originally, we noticed that the CRuby
behavior did not match the header documentation, so we opted not to
support it. However, this has now been fixed in CRuby [1], so we can fix
it here as well.

[1]: ruby/ruby#10169
thomasmarshall added a commit to Shopify/truffleruby that referenced this pull request Mar 6, 2024
This commit adds support for a null pointer to be passed as the encoding
argument to rb_enc_interned_str_cstr.

When we implemented this function originally, we noticed that the CRuby
behavior did not match the header documentation, so we opted not to
support it. However, this has now been fixed in CRuby [1], so we can fix
it here as well.

[1]: ruby/ruby#10169
thomasmarshall added a commit to Shopify/truffleruby that referenced this pull request Mar 13, 2024
This commit adds support for a null pointer to be passed as the encoding
argument to rb_enc_interned_str_cstr.

When we implemented this function originally, we noticed that the CRuby
behavior did not match the header documentation, so we opted not to
support it. However, this has now been fixed in CRuby [1], so we can fix
it here as well.

[1]: ruby/ruby#10169
thomasmarshall added a commit to Shopify/truffleruby that referenced this pull request Mar 13, 2024
This commit adds support for a null pointer to be passed as the encoding
argument to rb_enc_interned_str_cstr.

When we implemented this function originally, we noticed that the CRuby
behavior did not match the header documentation, so we opted not to
support it. However, this has now been fixed in CRuby [1], so we can fix
it here as well.

[1]: ruby/ruby#10169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants