ensure ibf_load_setup is only passed String params

In cases where RubyVM::InstructionSequence.load_from_binary() is
passed a param other than a String, we attempt to call the
RSTRING_LENINT macro on it which can cause a segfault.

ex:
```
var_0 = 0
RubyVM::InstructionSequence.load_from_binary(var_0)
```

This commit adds a type check to raise unless we are provided
a String.
This commit is contained in:
Zack Deveau 2024-04-19 16:53:05 -04:00 коммит произвёл Nobuyoshi Nakada
Родитель 23be6599a2
Коммит 9555a997ac
2 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -14214,6 +14214,8 @@ ibf_load_setup_bytes(struct ibf_load *load, VALUE loader_obj, const char *bytes,
static void
ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str)
{
StringValue(str);
if (RSTRING_LENINT(str) < (int)sizeof(struct ibf_header)) {
rb_raise(rb_eRuntimeError, "broken binary format");
}

Просмотреть файл

@ -850,4 +850,11 @@ class TestISeq < Test::Unit::TestCase
RubyVM::InstructionSequence.compile_prism(Object.new)
end
end
def test_load_from_binary_only_accepts_string_param
assert_raise(TypeError) do
var_0 = 0
RubyVM::InstructionSequence.load_from_binary(var_0)
end
end
end