Skip to content

Commit 70fafef

Browse files
rossberggumb0
authored andcommitted
[interpreter/test] Fix table limits (WebAssembly#1160)
1 parent c559d91 commit 70fafef

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

interpreter/valid/valid.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ and check_block (c : context) (es : instr list) (ts : stack_type) at =
310310
(* Types *)
311311

312312
let check_limits {min; max} range at msg =
313-
require (I64.le_u (Int64.of_int32 min) range) at msg;
313+
require (I32.le_u min range) at msg;
314314
match max with
315315
| None -> ()
316316
| Some max ->
317-
require (I64.le_u (Int64.of_int32 max) range) at msg;
317+
require (I32.le_u max range) at msg;
318318
require (I32.le_u min max) at
319319
"size minimum must not be greater than maximum"
320320

@@ -329,11 +329,11 @@ let check_func_type (ft : func_type) at =
329329

330330
let check_table_type (tt : table_type) at =
331331
let TableType (lim, _) = tt in
332-
check_limits lim 0x1_0000_0000L at "table size must be at most 2^32"
332+
check_limits lim 0xffff_ffffl at "table size must be at most 2^32-1"
333333

334334
let check_memory_type (mt : memory_type) at =
335335
let MemoryType lim = mt in
336-
check_limits lim 0x1_0000L at
336+
check_limits lim 0x1_0000l at
337337
"memory size must be at most 65536 pages (4GiB)"
338338

339339
let check_global_type (gt : global_type) at =

test/core/memory.wast

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
;; Test memory section structure
22

3+
(module (memory 0))
4+
(module (memory 1))
35
(module (memory 0 0))
46
(module (memory 0 1))
57
(module (memory 1 256))
@@ -74,6 +76,19 @@
7476
"memory size must be at most 65536 pages (4GiB)"
7577
)
7678

79+
(assert_malformed
80+
(module quote "(memory 0x1_0000_0000)")
81+
"i32 constant out of range"
82+
)
83+
(assert_malformed
84+
(module quote "(memory 0x1_0000_0000 0x1_0000_0000)")
85+
"i32 constant out of range"
86+
)
87+
(assert_malformed
88+
(module quote "(memory 0 0x1_0000_0000)")
89+
"i32 constant out of range"
90+
)
91+
7792
(module
7893
(memory 1)
7994
(data (i32.const 0) "ABC\a7D") (data (i32.const 20) "WASM")

test/core/table.wast

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
;; Test table section structure
2+
3+
(module (table 0 funcref))
4+
(module (table 1 funcref))
5+
(module (table 0 0 funcref))
6+
(module (table 0 1 funcref))
7+
(module (table 1 256 funcref))
8+
(module (table 0 65536 funcref))
9+
(module (table 0 0xffff_ffff funcref))
10+
11+
(assert_invalid (module (table 0 funcref) (table 0 funcref)) "multiple tables")
12+
(assert_invalid (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) "multiple tables")
13+
14+
(assert_invalid (module (elem (i32.const 0))) "unknown table")
15+
(assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table")
16+
17+
18+
(assert_invalid
19+
(module (table 1 0 funcref))
20+
"size minimum must not be greater than maximum"
21+
)
22+
(assert_invalid
23+
(module (table 0xffff_ffff 0 funcref))
24+
"size minimum must not be greater than maximum"
25+
)
26+
27+
(assert_malformed
28+
(module quote "(table 0x1_0000_0000 funcref)")
29+
"i32 constant out of range"
30+
)
31+
(assert_malformed
32+
(module quote "(table 0x1_0000_0000 0x1_0000_0000 funcref)")
33+
"i32 constant out of range"
34+
)
35+
(assert_malformed
36+
(module quote "(table 0 0x1_0000_0000 funcref)")
37+
"i32 constant out of range"
38+
)
39+
40+
141
;; Duplicate table identifiers
242

343
(assert_malformed (module quote

0 commit comments

Comments
 (0)