LibWasm: Validate number of data sections

This commit is contained in:
Diego 2024-06-10 12:42:13 -07:00 committed by Ali Mohammad Pur
commit e64ac8c177
Notes: sideshowbarker 2024-07-17 06:33:00 +09:00
2 changed files with 7 additions and 0 deletions

View file

@ -41,6 +41,10 @@ ErrorOr<void, ValidationError> Validator::validate(Module& module)
m_context.types.extend(section.types());
});
module.for_each_section_of_type<DataCountSection>([this](DataCountSection const& section) {
m_context.data_count = section.count();
});
module.for_each_section_of_type<ImportSection>([&](ImportSection const& section) {
for (auto& import_ : section.imports()) {
import_.description().visit(
@ -177,6 +181,8 @@ ErrorOr<void, ValidationError> Validator::validate(StartSection const& section)
ErrorOr<void, ValidationError> Validator::validate(DataSection const& section)
{
if (m_context.data_count.has_value() && section.data().size() != m_context.data_count)
return Errors::invalid("data count does not match segment count"sv);
for (auto& entry : section.data()) {
TRY(entry.value().visit(
[](DataSection::Data::Passive const&) { return ErrorOr<void, ValidationError> {}; },

View file

@ -27,6 +27,7 @@ struct Context {
COWVector<bool> datas;
COWVector<ValueType> locals;
COWVector<ResultType> labels;
Optional<u32> data_count;
Optional<ResultType> return_;
AK::HashTable<FunctionIndex> references;
size_t imported_function_count { 0 };