From c4d4c657d09753f287e7a92c33771f0b57b6fc5f Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 6 Jul 2021 14:03:54 +0430 Subject: [PATCH] LibWasm: Limit module memory to 65536 pages The spec mentions this, and anything past that can't be correctly addressed by the 32-bit indices anyhow. --- Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index 95cc31771b..29d3c414b8 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -350,6 +350,9 @@ public: if (size_to_grow == 0) return true; auto new_size = m_data.size() + size_to_grow; + // Can't grow past 2^16 pages. + if (new_size >= Constants::page_size * 65536) + return false; if (auto max = m_type.limits().max(); max.has_value()) { if (max.value() * Constants::page_size < new_size) return false;