From 4a08bb7e24f7bade6f596bf4ccabe257ccf20c0e Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 26 Mar 2026 07:34:07 -0700 Subject: [PATCH 1/2] Fix crash reporter NULL dereference with ractors (#16561) rb_ec_ractor_ptr(ec) can return NULL when ec->thread_ptr is NULL (e.g. when crashing from a GC free function). Dereferencing the NULL return value crashes the bug reporter itself, causing "Crashed while printing bug report" and losing all diagnostic information. Similarly, ec->thread_ptr can be NULL, so guard the scheduler check. --- vm_dump.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vm_dump.c b/vm_dump.c index e2b4804ab0d583..4864ccf58bdb30 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -1435,8 +1435,11 @@ rb_vm_bugreport(const void *ctx, FILE *errout) kprintf("-- Threading information " "---------------------------------------------------\n"); kprintf("Total ractor count: %u\n", vm->ractor.cnt); - kprintf("Ruby thread count for this ractor: %u\n", rb_ec_ractor_ptr(ec)->threads.cnt); - if (ec->thread_ptr->scheduler != Qnil) { + const rb_ractor_t *cr = rb_ec_ractor_ptr(ec); + if (cr) { + kprintf("Ruby thread count for this ractor: %u\n", cr->threads.cnt); + } + if (ec->thread_ptr && ec->thread_ptr->scheduler != Qnil) { kprintf("Note that the Fiber scheduler is enabled\n"); } kputs("\n"); From afe5f77a2610a6dfcb0df196723cd2e7012208d6 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 26 Mar 2026 16:42:02 +0100 Subject: [PATCH 2/2] [ruby/json] Keep Integer#to_json optimized and adapt the test * Redefining Integer#to_s is bound to break many things, any non-segfault outcome should be acceptable. So adapt the test to just ensure it does not segfault. * Also redefining Kernel#String would also break with the previous code. https://github.com/ruby/json/commit/ac0670b20b --- test/json/json_generator_test.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb index 00960dffee8d7f..0eb85a82653e7c 100755 --- a/test/json/json_generator_test.rb +++ b/test/json/json_generator_test.rb @@ -504,10 +504,14 @@ def to_s end alias_method :to_s, :to_s end - case RUBY_PLATFORM - when "java" + case RUBY_ENGINE + when "jruby" assert_equal bignum_to_s, JSON.generate(bignum) - else + when "truffleruby" + assert_raise(NoMethodError) do + JSON.generate(bignum) + end + when "ruby" assert_raise(TypeError) do JSON.generate(bignum) end