From 67749300c301faec825e6f0b215f4eae89adc3b6 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:59:31 -0700 Subject: [PATCH] LibWasm: Validate that data section exists for some instructions --- Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp index 50bb5703dd9..2606e394cca 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Validator.cpp @@ -1950,6 +1950,8 @@ VALIDATE_INSTRUCTION(memory_copy) 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(); @@ -1963,6 +1965,9 @@ VALIDATE_INSTRUCTION(memory_init) 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(); TRY(validate(index));