From 85e95e315a8023c46eb804fe80ebc244bcfdae3e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 24 Jan 2019 13:12:36 -0800 Subject: [PATCH] validate all function indexes in binary reading (#1887) fixes bug reported in comment on e63c4a7 , #1885 (comment) , #1879 (comment) --- src/wasm/wasm-binary.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ac68cbe566d..187328e587c 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -967,6 +967,9 @@ void WasmBinaryBuilder::readSignatures() { } Name WasmBinaryBuilder::getFunctionIndexName(Index i) { + if (i >= wasm.functions.size()) { + throwError("invalid function index"); + } return wasm.functions[i]->name; } @@ -1505,9 +1508,6 @@ void WasmBinaryBuilder::processFunctions() { auto index = exportIndexes[curr]; switch (curr->kind) { case ExternalKind::Function: { - if (index >= wasm.functions.size()) { - throwError("bad function export index"); - } curr->value = getFunctionIndexName(index); break; }