From aa4bb95d9c6a30a4fd48ba349f6f7fdcb76d32ed Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Sun, 5 May 2019 09:29:37 +0200 Subject: [PATCH] Check overflow of reference and closure tables --- src/compile.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/compile.ml b/src/compile.ml index 3f3f6bb72e1..258d76cf2cc 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -758,6 +758,12 @@ module ElemHeap = struct reference table *) let remember_reference env : G.t = Func.share_code1 env "remember_reference" ("ref", I32Type) [I32Type] (fun env get_ref -> + (* Check table space *) + get_ref_ctr ^^ + compile_unboxed_const max_references ^^ + G.i (Compare (Wasm.Values.I32 I64Op.LtU)) ^^ + E.else_trap_with env "Reference table full" ^^ + (* Return index *) get_ref_ctr ^^ @@ -811,6 +817,12 @@ module ClosureTable = struct reference table *) let remember_closure env : G.t = Func.share_code1 env "remember_closure" ("ptr", I32Type) [I32Type] (fun env get_ptr -> + (* Check table space *) + get_counter ^^ + compile_unboxed_const (Int32.sub max_entries 1l) ^^ + G.i (Compare (Wasm.Values.I32 I64Op.LtU)) ^^ + E.else_trap_with env "Closure table full" ^^ + (* Return index *) get_counter ^^ compile_add_const 1l ^^