LibWasm: Check data segment offset at correct time during instantiation

The data segment offset should be checked _before_ checking if the
contents of the segment are non-existent.
This commit is contained in:
Diego 2024-06-16 07:12:43 -07:00 committed by Ali Mohammad Pur
parent c2a0c4f581
commit 78c56d80f9
Notes: sideshowbarker 2024-07-17 03:14:39 +09:00

View file

@ -392,8 +392,6 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
}
main_module_instance.datas().append(*maybe_data_address);
if (data.init.is_empty())
return;
auto address = main_module_instance.memories()[data.index.value()];
auto instance = m_store.get(address);
Checked<size_t> checked_offset = data.init.size();
@ -405,6 +403,8 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
};
return;
}
if (data.init.is_empty())
return;
instance->data().overwrite(offset, data.init.data(), data.init.size());
},
[&](DataSection::Data::Passive const& passive) {