1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +00:00

LibWasm: Tolerate modules with invalid sections and mark them as invalid

We should not crash, but rather just fail to verify them.
This commit is contained in:
Ali Mohammad Pur 2021-12-09 21:32:01 +03:30 committed by Ali Mohammad Pur
parent 2db27be2df
commit ed9e7f1ad0
2 changed files with 15 additions and 5 deletions

View file

@ -1363,16 +1363,22 @@ ParseResult<Module> Module::parse(InputStream& stream)
return Module { move(sections) };
}
void Module::populate_sections()
bool Module::populate_sections()
{
auto is_ok = true;
FunctionSection const* function_section { nullptr };
for_each_section_of_type<FunctionSection>([&](FunctionSection const& section) { function_section = &section; });
for_each_section_of_type<CodeSection>([&](CodeSection const& section) {
// FIXME: This should be considered invalid once validation is implemented.
if (!function_section)
if (!function_section) {
is_ok = false;
return;
}
size_t index = 0;
for (auto& entry : section.functions()) {
if (function_section->types().size() <= index) {
is_ok = false;
return;
}
auto& type_index = function_section->types()[index];
Vector<ValueType> locals;
for (auto& local : entry.func().locals()) {
@ -1383,6 +1389,7 @@ void Module::populate_sections()
++index;
}
});
return is_ok;
}
String parse_error_to_string(ParseError error)