diff --git a/iseq.c b/iseq.c index 28c2d4f80b..4f1c39d2ae 100644 --- a/iseq.c +++ b/iseq.c @@ -1485,6 +1485,7 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self) pm_string_mapped_init(&input, RSTRING_PTR(file)); } else { + Check_Type(src, T_STRING); input.source = (const uint8_t *)RSTRING_PTR(src); input.length = RSTRING_LEN(src); input.type = PM_STRING_SHARED; diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index dd81610b53..35bf36e492 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -809,4 +809,10 @@ class TestISeq < Test::Unit::TestCase end end end + + def test_compile_prism_with_invalid_object_type + assert_raise(TypeError) do + RubyVM::InstructionSequence.compile_prism(Object.new) + end + end end