Skip to content

Commit

Permalink
LibWasm: Validate number of data sections
Browse files Browse the repository at this point in the history
  • Loading branch information
dzfrias authored and alimpfard committed Jun 10, 2024
1 parent a9f3afc commit e64ac8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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> {}; },
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWasm/AbstractMachine/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit e64ac8c

Please sign in to comment.