wasmerio/wasmer · error
getting invalid type from table, handle this error
Error message
getting invalid type from table, handle this error
What it means
Table::get reads the raw table element and matches on the table's declared ValType; only ExternRef and FuncRef are handled. Any other ValType (should be impossible for a reference table) hits `todo!` — a defensive panic meant to be replaced with a proper error if invalid table types ever occur.
Source
Thrown at lib/vm/src/table.rs:245
// update table definition
unsafe {
let mut td_ptr = self.get_vm_table_definition();
let td = td_ptr.as_mut();
td.current_elements = new_len;
td.base = self.vec.as_mut_ptr() as _;
}
Some(size)
}
/// Get reference to the specified element.
///
/// Returns `None` if the index is out of bounds.
pub fn get(&self, index: u32) -> Option<TableElement> {
let raw_data = self.vec.get(index as usize).cloned()?;
Some(match self.table.ty {
ValType::ExternRef => TableElement::ExternRef(unsafe { raw_data.extern_ref }),
ValType::FuncRef => TableElement::FuncRef(unsafe { raw_data.func_ref }),
_ => todo!("getting invalid type from table, handle this error"),
})
}
/// Set reference to the specified element.
///
/// # Errors
///
/// Returns an error if the index is out of bounds.
pub fn set(&mut self, index: u32, reference: TableElement) -> Result<(), Trap> {
self.set_with_construction(index, reference, false)
}
pub(crate) fn set_with_construction(
&mut self,
index: u32,
reference: TableElement,
in_construction: bool,
) -> Result<(), Trap> {View on GitHub (pinned to 8c4b9ee9d3)
Solutions
- Only create tables via validated wasm or with Type limited to funcref/externref element types
- Replace the todo! with a returned error/internal assertion so misuse surfaces as TableError instead of a panic
- Audit embedder code that constructs Table/Type manually and fix the element ValType
- Upgrade wasmer if a newly supported reference type needs handling here
Example fix
// before
_ => todo!("getting invalid type from table, handle this error"),
// after
_ => return None, // or record unreachable: tables may only hold references Defensive patterns
Strategy: type-guard
Validate before calling
// validate table element type before creating/accessing
fn table_type_is_reference(ty: &ValType) -> bool {
matches!(ty, ValType::ExternRef | ValType::FuncRef)
} Type guard
fn elem_type_ok(table_type: &TableType) -> bool {
matches!(table_type.ty, ValType::ExternRef | ValType::FuncRef)
} Try / catch
// Table::get panics rather than returning Result; wrap table creation instead
let table = Table::new(store, TableType { ty: ValType::FuncRef, ..ty })?; // validated upstream
// then get() can only see FuncRef/ExternRef Prevention
- Construct tables only via validated wasm imports/exports, not hand-built ValTypes
- Validate TableType.ty is funcref/externref before Table::new
- Update the match if new reference types (e.g. exnref) are introduced
- Prefer API paths that return TableError over raw accessors
When it happens
Trigger: Calling Table::get (directly or via table.copy's copy_within) on a table whose `table.ty` is neither ExternRef nor FuncRef, or on a table whose type descriptor got corrupted/misinitialized so the ValType match falls through.
Common situations: Embedders constructing tables programmatically (via Table::new with a Type carrying an unexpected ValType) rather than through wasm validation; fuzzing or memory corruption producing an out-of-contract table type; a wasmer version where table types were extended without updating this match.
Related errors
- unimplemented operator {operator:?}
- global #{} is a constant
- Cannot load reference type
- Unhandled inner case
- ref.is_null only accepts reference types
AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01).
Data as JSON: /api/errors/5b82253165b9b88f.
Report an issue: GitHub.