LibWasm: Validate that data section exists for some instructions

(cherry picked from commit 5e5df136849c1d450a6e0dd4af3805f7e56f6e76)
This commit is contained in:
Diego 2024-06-10 15:59:31 -07:00 committed by Ali Mohammad Pur
parent be3bc9bd7c
commit 985c4c590d

View file

@ -1950,6 +1950,8 @@ VALIDATE_INSTRUCTION(memory_copy)
VALIDATE_INSTRUCTION(memory_init) VALIDATE_INSTRUCTION(memory_init)
{ {
if (!m_context.data_count.has_value())
return Errors::invalid("memory.init, requires data count section"sv);
auto& args = instruction.arguments().get<Instruction::MemoryInitArgs>(); auto& args = instruction.arguments().get<Instruction::MemoryInitArgs>();
@ -1963,6 +1965,9 @@ VALIDATE_INSTRUCTION(memory_init)
VALIDATE_INSTRUCTION(data_drop) VALIDATE_INSTRUCTION(data_drop)
{ {
if (!m_context.data_count.has_value())
return Errors::invalid("data.drop, requires data count section"sv);
auto index = instruction.arguments().get<DataIndex>(); auto index = instruction.arguments().get<DataIndex>();
TRY(validate(index)); TRY(validate(index));