Skip to content

Commit

Permalink
fix candid decoding at immutable array type to handle defaulting unde…
Browse files Browse the repository at this point in the history
…r opt correctly
  • Loading branch information
crusso committed Oct 10, 2023
1 parent 7ff838c commit 4d84e78
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 35 deletions.
10 changes: 7 additions & 3 deletions src/codegen/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6693,7 +6693,7 @@ module MakeSerialization (Strm : Stream) = struct
begin code0
end begin
get_b ^^ compile_eq_const 1l ^^
E.else_trap_with env ("IDL error: byte tag not 0 or 1") ^^
E.else_trap_with env ("IDL error: byte tag not 0 or 1") ^^
code1
end
| _ -> assert false; (* can be generalized later as needed *)
Expand Down Expand Up @@ -7062,6 +7062,8 @@ module MakeSerialization (Strm : Stream) = struct
let (set_x, get_x) = new_local env "x" in
let (set_val, get_val) = new_local env "val" in
let (set_arg_typ, get_arg_typ) = new_local env "arg_typ" in
(* TODO: if possible refactor to match new Array t code,
(though probably unnecessary for extended candid due to lack of fancy opt subtyping) *)
with_composite_arg_typ get_array_typ idl_vec (ReadBuf.read_sleb128 env) ^^ set_arg_typ ^^
ReadBuf.read_leb128 env get_data_buf ^^ set_len ^^
get_len ^^ Arr.alloc env ^^ set_x ^^
Expand Down Expand Up @@ -7102,7 +7104,9 @@ module MakeSerialization (Strm : Stream) = struct
let (set_x, get_x) = new_local env "x" in
let (set_val, get_val) = new_local env "val" in
let (set_arg_typ, get_arg_typ) = new_local env "arg_typ" in
with_composite_typ idl_vec (ReadBuf.read_sleb128 env) ^^ set_arg_typ ^^
with_composite_typ idl_vec (fun get_typ_buf ->
ReadBuf.read_sleb128 env get_typ_buf ^^
set_arg_typ ^^
ReadBuf.read_leb128 env get_data_buf ^^ set_len ^^
get_len ^^ Arr.alloc env ^^ set_x ^^
get_len ^^ from_0_to_n env (fun get_i ->
Expand All @@ -7112,7 +7116,7 @@ module MakeSerialization (Strm : Stream) = struct
get_val ^^ store_ptr
) ^^
get_x ^^
Tagged.allocation_barrier env
Tagged.allocation_barrier env)
| Opt t ->
check_prim_typ (Prim Null) ^^
G.if1 I32Type (Opt.null_lit env)
Expand Down
15 changes: 0 additions & 15 deletions test/run/ok/idl-decoding-bug.wasm-run.ok

This file was deleted.

1 change: 0 additions & 1 deletion test/run/ok/idl-decoding-bug.wasm-run.ret.ok

This file was deleted.

17 changes: 2 additions & 15 deletions test/run/ok/idl-opt-tests.wasm-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,5 @@ null
null
null
?null
IDL error: byte read out of buffer
Error: failed to run main module `_out/idl-opt-tests.wasm`

Caused by:
0: failed to invoke command default
1: error while executing at wasm backtrace:
0: rts_trap
1: motoko_rts::trap_with_prefix::h757ee6d860f5c7ff
2: motoko_rts::idl_trap_with::h539f381c213e508f
3: leb128_decode
4: @deserialize_go<vN>
5: @deserialize<vN>
6: init
7: _start
2: wasm trap: unreachable
null
null
1 change: 0 additions & 1 deletion test/run/ok/idl-opt-tests.wasm-run.ret.ok

This file was deleted.

0 comments on commit 4d84e78

Please sign in to comment.