← All issues

[Memory64] Wasm table imports don't check that the address type matches

Wasm table linking checked type, size, and max — everything but the address width.

Component: JSC WebAssembly | 862994e

WebAssembly's Memory64 proposal lets tables (and memories) be indexed with either i32 or i64 addresses. The JIT and interpreter emit different indexing code depending on which address type a table declares, because address width changes offset computation and bounds checks for call_indirect, table.get/table.set, and similar ops. Import validation is meant to be the boundary that guarantees a module only ever operates on tables matching its statically declared assumptions.

Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp

if (!Wasm::isSubtype(actualType, expectedType) || !Wasm::isSubtype(expectedType, actualType))
return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "Table import"_s, "provided a 'type' that is wrong"_s)));
 
+ if (table->table()->addressType() != moduleInformation.tables[import.kindIndex].addressType())
+ return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "Table import"_s, "provided an 'address' that is different from the module's declared 'address' import table attribute"_s)));
+
// ii. Append v to tables.
// iii. Append v.[[Table]] to imports.
m_instance->setTable(vm, import.kindIndex, table);

Table import linking previously validated element type, initial size, and maximum size, but never compared the provided table's addressType() against the module's declared import addressType(). The patch adds that cross-check and throws a LinkError on mismatch, so an i32 table can no longer satisfy a table64 import (or vice versa).

Without the check, a module compiled to assume 64-bit table indices could be linked against a table object backed by 32-bit indexing internals. Index and bounds-check code generated for one address width would then run against a table laid out for the other — an address-width confusion at the Wasm linking boundary, the type-confusion class applied to table addressing.