From d52a26de3f069eea9d947c9659a522afd615cbec Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 2 Sep 2021 13:08:12 +0430 Subject: [PATCH] LibWasm: Move the vector size limit to Constants.h and increase it a bit --- Userland/Libraries/LibWasm/Constants.h | 1 + Userland/Libraries/LibWasm/Parser/Parser.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWasm/Constants.h b/Userland/Libraries/LibWasm/Constants.h index de2e8481eb..4c76a79fde 100644 --- a/Userland/Libraries/LibWasm/Constants.h +++ b/Userland/Libraries/LibWasm/Constants.h @@ -40,6 +40,7 @@ static constexpr auto page_size = 64 * KiB; // These are not concretely defined by the spec, so the values are only defined by us. static constexpr auto minimum_stack_space_to_keep_free = 256 * KiB; // Note: Value is arbitrary and chosen by testing with ASAN static constexpr auto max_allowed_executed_instructions_per_call = 256 * 1024 * 1024; +static constexpr auto max_allowed_vector_size = 2 * MiB; static constexpr auto max_allowed_function_locals_per_type = 420; // Note: VERY arbitrary. } diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 53c95522da..e73b75d2b3 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -54,7 +54,7 @@ static auto parse_vector(InputStream& stream) return ParseResult> { with_eof_check(stream, ParseError::ExpectedSize) }; entries.append(value); } else if constexpr (IsSame) { - if (count > 64 * KiB) + if (count > Constants::max_allowed_vector_size) return ParseResult> { ParseError::HugeAllocationRequested }; entries.resize(count); if (!stream.read_or_error({ entries.data(), entries.size() }))