From 29811a120d8dfa04abb8024b3442053269f86ccb Mon Sep 17 00:00:00 2001 From: Jan Olaf Martin Date: Wed, 7 Aug 2024 08:17:17 -0700 Subject: [PATCH] Allow all LEB128 encodings of zero for table index Even without reference types, the table index can be encoded in multiple ways (e.g. `0x80 0x00`). This fixes the handling of these (valid) files by always reading the table index as a LEB128. --- core/iwasm/interpreter/wasm_loader.c | 5 ----- core/iwasm/interpreter/wasm_mini_loader.c | 5 ----- 2 files changed, 10 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 785b28980c..09787bb61c 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -12082,12 +12082,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, WASMFuncType *func_type; read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 read_leb_uint32(p, p_end, table_idx); -#else - CHECK_BUF(p, p_end, 1); - table_idx = read_uint8(p); -#endif if (!check_table_index(module, table_idx, error_buf, error_buf_size)) { goto fail; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 0012b84ae6..d0d4e0027e 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -6592,12 +6592,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 read_leb_uint32(p, p_end, table_idx); -#else - CHECK_BUF(p, p_end, 1); - table_idx = read_uint8(p); -#endif if (!check_table_index(module, table_idx, error_buf, error_buf_size)) { goto fail;