Skip to content

Commit e126fd1

Browse files
authored
Fix panicking overflow when calculating table sizes (#13244)
Return an error instead of panicking in the same manner that OOM is handled.
1 parent 812e9cf commit e126fd1

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

RELEASES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 44.0.1
2+
3+
Released 2026-04-30.
4+
5+
### Fixed
6+
7+
* Panic when allocating a table exceeding the size of the host's address space.
8+
[GHSA-p8xm-42r7-89xg](https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-p8xm-42r7-89xg)
9+
10+
--------------------------------------------------------------------------------
11+
112
## 44.0.0
213

314
Released 2026-04-20.

crates/wasmtime/src/runtime/vm/table.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ unsafe fn alloc_dynamic_table_elements<T>(len: usize) -> Result<TryVec<Option<T>
309309

310310
let size = mem::size_of::<Option<T>>();
311311
let size = size.next_multiple_of(align);
312-
let size = size.checked_mul(len).unwrap();
312+
let size = size
313+
.checked_mul(len)
314+
.ok_or_else(|| format_err!("overflow calculating table allocation size"))?;
313315

314316
let layout = Layout::from_size_align(size, align)?;
315317

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;;! memory64 = true
2+
;;! hogs_memory = true
3+
;;! reference_types = true
4+
5+
(assert_trap
6+
(module (table i64 0x2000_0000_0000_0000 funcref))
7+
"overflow calculating table allocation size")
8+
9+
(module
10+
(table i64 0 funcref)
11+
(func (export "grow") (param i64) (result i64)
12+
(table.grow 0 (ref.null func) (local.get 0))
13+
)
14+
)
15+
16+
(assert_trap (invoke "grow" (i64.const 0x2000_0000_0000_0000))
17+
"failed to allocate")

0 commit comments

Comments
 (0)