From 602bbf6e22acedae329406719a909873ad0b8bb8 Mon Sep 17 00:00:00 2001 From: ksss Date: Mon, 19 Jan 2026 10:56:21 +0900 Subject: [PATCH] Fix SEGV on `#add_{required,optional}_child` --- ext/rbs_extension/legacy_location.c | 3 +++ test/rbs/location_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ext/rbs_extension/legacy_location.c b/ext/rbs_extension/legacy_location.c index 603136291..35833cc6d 100644 --- a/ext/rbs_extension/legacy_location.c +++ b/ext/rbs_extension/legacy_location.c @@ -169,6 +169,9 @@ static VALUE location_end_pos(VALUE self) { } static rbs_constant_id_t rbs_constant_pool_insert_ruby_symbol(VALUE symbol) { + if (!RB_TYPE_P(symbol, T_SYMBOL)) { + rb_raise(rb_eTypeError, "wrong argument type %" PRIsVALUE " (must be a Symbol)", rb_obj_class(symbol)); + } VALUE name = rb_sym2str(symbol); // Constants inserted here will never be freed, but that's acceptable because: diff --git a/test/rbs/location_test.rb b/test/rbs/location_test.rb index 5d8e8e4d2..a102cf49e 100644 --- a/test/rbs/location_test.rb +++ b/test/rbs/location_test.rb @@ -39,6 +39,16 @@ def test_location_child end end + def test_location_add_required_child_with_invalid_argument + loc = Location.new(buffer, 0, 8) + assert_raise(TypeError) { loc.add_required_child("string", 0...6) } + end + + def test_location_add_optional_child_with_invalid_argument + loc = Location.new(buffer, 0, 8) + assert_raise(TypeError) { loc.add_optional_child("string", 0...6) } + end + def test_location_initialize_copy loc = Location.new(buffer, 0, 8) loc.add_optional_child(:num, 0...2)