mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 09:36:08 +00:00
LibWasm: Validate number of data sections
This commit is contained in:
parent
a9f3afc29b
commit
e64ac8c177
Notes:
sideshowbarker
2024-07-17 06:33:00 +09:00
Author: https://github.com/dzfrias
Commit: e64ac8c177
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/134
2 changed files with 7 additions and 0 deletions
|
@ -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> {}; },
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue