Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions interpreter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ $(ZIP): $(WINMAKE)
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD

test: $(NAME)
../test/core/run.py --wasm `pwd`/wasm $(if $(JS),--js '$(JS)',)
../test/core/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',)

test/%: $(NAME)
../test/core/run.py --wasm `pwd`/wasm $(if $(JS),--js '$(JS)',) $(@:test/%=../test/core/%.wast)
../test/core/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',) $(@:test/%=../test/core/%.wast)

run/%: $(NAME)
./$(NAME) $(@:run/%=../test/core/%.wast)

clean:
$(OCB) -clean
Expand Down
6 changes: 4 additions & 2 deletions interpreter/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ let init_table (inst : instance) (seg : table_segment) =
let {index; offset = const; init} = seg.it in
let tab = table inst index in
let offset = i32 (eval_const inst const) const.at in
let end_ = Int32.(add offset (of_int (List.length init))) in
let bound = Table.size tab in
if I32.lt_u bound Int32.(add offset (of_int (List.length init))) then
if I32.lt_u bound end_ || I32.lt_u end_ offset then
Link.error seg.at "elements segment does not fit table";
fun () -> Table.blit tab offset (List.map (fun x -> Func (func inst x)) init)

Expand All @@ -374,8 +375,9 @@ let init_memory (inst : instance) (seg : memory_segment) =
let mem = memory inst index in
let offset' = i32 (eval_const inst const) const.at in
let offset = I64_convert.extend_u_i32 offset' in
let end_ = Int64.(add offset (of_int (String.length init))) in
let bound = Memory.bound mem in
if I64.lt_u bound Int64.(add offset (of_int (String.length init))) then
if I64.lt_u bound end_ || I64.lt_u end_ offset then
Link.error seg.at "data segment does not fit memory";
fun () -> Memory.blit mem offset init

Expand Down
34 changes: 33 additions & 1 deletion test/core/call_indirect.wast
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,40 @@
"unknown type"
)

;; invalid table

;; Unbound function in table

(assert_invalid
(module (table anyfunc (elem 0 0)))
"unknown function 0"
)


;; Invalid bounds for elements

(assert_unlinkable
(module
(table 10 anyfunc)
(elem (i32.const 10) $f)
(func $f)
)
"elements segment does not fit"
)

(assert_unlinkable
(module
(table 10 anyfunc)
(elem (i32.const -1) $f)
(func $f)
)
"elements segment does not fit"
)

(assert_unlinkable
(module
(table 10 anyfunc)
(elem (i32.const -10) $f)
(func $f)
)
"elements segment does not fit"
)
17 changes: 16 additions & 1 deletion test/core/memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
(module (memory 0 1) (data (i32.const 0) "a"))
"data segment does not fit"
)
(assert_unlinkable
(module (memory 1 2) (data (i32.const -1) "a"))
"data segment does not fit"
)
(assert_unlinkable
(module (memory 1 2) (data (i32.const -1000) "a"))
"data segment does not fit"
)
(assert_unlinkable
(module (memory 1 2) (data (i32.const 0) "a") (data (i32.const 98304) "b"))
"data segment does not fit"
Expand All @@ -93,13 +101,20 @@
(module (memory 1) (data (i32.const 0x12000) ""))
"data segment does not fit"
)
(assert_unlinkable
(module (memory 1 2) (data (i32.const -1) ""))
"data segment does not fit"
)
;; This seems to cause a time-out on Travis.
(;assert_unlinkable
(module (memory 0x10000) (data (i32.const 0xffffffff) "ab"))
"" ;; either out of memory or segment does not fit
;)
(assert_unlinkable
(module (global (import "spectest" "global") i32) (memory 0) (data (get_global 0) "a"))
(module
(global (import "spectest" "global") i32)
(memory 0) (data (get_global 0) "a")
)
"data segment does not fit"
)

Expand Down