瀏覽代碼

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.
Ali Mohammad Pur 4 年之前
父節點
當前提交
c4d4c657d0
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h

+ 3 - 0
Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h

@@ -350,6 +350,9 @@ public:
         if (size_to_grow == 0)
         if (size_to_grow == 0)
             return true;
             return true;
         auto new_size = m_data.size() + size_to_grow;
         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 (auto max = m_type.limits().max(); max.has_value()) {
             if (max.value() * Constants::page_size < new_size)
             if (max.value() * Constants::page_size < new_size)
                 return false;
                 return false;