Skip to content

Commit

Permalink
[interpreter] Change error messages to say 'malformed' for binary (#1149
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rossberg authored Mar 23, 2020
1 parent 4df5e54 commit e84c676
Show file tree
Hide file tree
Showing 9 changed files with 762 additions and 762 deletions.
18 changes: 9 additions & 9 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ let vec f s = let n = len32 s in list f n s
let name s =
let pos = pos s in
try Utf8.decode (string s) with Utf8.Utf8 ->
error s pos "invalid UTF-8 encoding"
error s pos "malformed UTF-8 encoding"

let sized f s =
let size = len32 s in
Expand All @@ -137,12 +137,12 @@ let value_type s =
| -0x02 -> I64Type
| -0x03 -> F32Type
| -0x04 -> F64Type
| _ -> error s (pos s - 1) "invalid value type"
| _ -> error s (pos s - 1) "malformed value type"

let elem_type s =
match vs7 s with
| -0x10 -> FuncRefType
| _ -> error s (pos s - 1) "invalid element type"
| _ -> error s (pos s - 1) "malformed element type"

let stack_type s =
match peek s with
Expand All @@ -155,7 +155,7 @@ let func_type s =
let ins = vec value_type s in
let out = vec value_type s in
FuncType (ins, out)
| _ -> error s (pos s - 1) "invalid function type"
| _ -> error s (pos s - 1) "malformed function type"

let limits vu s =
let has_max = bool s in
Expand All @@ -176,7 +176,7 @@ let mutability s =
match u8 s with
| 0 -> Immutable
| 1 -> Mutable
| _ -> error s (pos s - 1) "invalid mutability"
| _ -> error s (pos s - 1) "malformed mutability"

let global_type s =
let t = value_type s in
Expand All @@ -196,7 +196,7 @@ let end_ s = expect 0x0b s "END opcode expected"

let memop s =
let align = vu32 s in
require (I32.le_u align 32l) s (pos s - 1) "invalid memop flags";
require (I32.le_u align 32l) s (pos s - 1) "malformed memop flags";
let offset = vu32 s in
Int32.to_int align, offset

Expand Down Expand Up @@ -467,7 +467,7 @@ let id s =
| 9 -> `ElemSection
| 10 -> `CodeSection
| 11 -> `DataSection
| _ -> error s (pos s) "invalid section id"
| _ -> error s (pos s) "malformed section id"
) bo

let section_with_size tag f default s =
Expand Down Expand Up @@ -495,7 +495,7 @@ let import_desc s =
| 0x01 -> TableImport (table_type s)
| 0x02 -> MemoryImport (memory_type s)
| 0x03 -> GlobalImport (global_type s)
| _ -> error s (pos s - 1) "invalid import kind"
| _ -> error s (pos s - 1) "malformed import kind"

let import s =
let module_name = name s in
Expand Down Expand Up @@ -552,7 +552,7 @@ let export_desc s =
| 0x01 -> TableExport (at var s)
| 0x02 -> MemoryExport (at var s)
| 0x03 -> GlobalExport (at var s)
| _ -> error s (pos s - 1) "invalid export kind"
| _ -> error s (pos s - 1) "malformed export kind"

let export s =
let name = name s in
Expand Down
2 changes: 1 addition & 1 deletion interpreter/text/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let nat32 s at =
try I32.of_string_u s with Failure _ -> error at "i32 constant out of range"

let name s at =
try Utf8.decode s with Utf8.Utf8 -> error at "invalid UTF-8 encoding"
try Utf8.decode s with Utf8.Utf8 -> error at "malformed UTF-8 encoding"


(* Symbolic variables *)
Expand Down
4 changes: 2 additions & 2 deletions test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@
"\0a\04\01" ;; code section
"\02\00\0b" ;; function body
)
"invalid value type"
"malformed value type"
)

;; 1 elem segment declared, 2 given
Expand Down Expand Up @@ -777,7 +777,7 @@
"\02" ;; break depth for default
"\0b\0b\0b" ;; end
)
"invalid value type"
"malformed value type"
)

;; Start section
Expand Down
4 changes: 2 additions & 2 deletions test/core/custom.wast
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
"\00\25\10" "a custom section" "this is the payload"
"\00\24\10" "a custom section" "this is the payload"
)
"invalid section id"
"malformed section id"
)

(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\07\01\60\02\7f\7f\01\7f" ;; type section
"\00\25\10" "a custom section" "this is the payload" ;; invalid length!
"\00\25\10" "a custom section" "this is the payload" ;; wrong length!
"\03\02\01\00" ;; function section
"\0a\09\01\07\00\20\00\20\01\6a\0b" ;; code section
"\00\1b\07" "custom2" "this is the payload" ;; custom section
Expand Down
16 changes: 8 additions & 8 deletions test/core/global.wast
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@
"\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
"\03" ;; GlobalImport
"\7f" ;; i32
"\02" ;; invalid mutability
"\02" ;; malformed mutability
)
"invalid mutability"
"malformed mutability"
)
(assert_malformed
(module binary
Expand All @@ -323,9 +323,9 @@
"\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
"\03" ;; GlobalImport
"\7f" ;; i32
"\ff" ;; invalid mutability
"\ff" ;; malformed mutability
)
"invalid mutability"
"malformed mutability"
)

(module
Expand All @@ -337,23 +337,23 @@
"\06\86\80\80\80\00" ;; global section
"\01" ;; length 1
"\7f" ;; i32
"\02" ;; invalid mutability
"\02" ;; malformed mutability
"\41\00" ;; i32.const 0
"\0b" ;; end
)
"invalid mutability"
"malformed mutability"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\06\86\80\80\80\00" ;; global section
"\01" ;; length 1
"\7f" ;; i32
"\ff" ;; invalid mutability
"\ff" ;; malformed mutability
"\41\00" ;; i32.const 0
"\0b" ;; end
)
"invalid mutability"
"malformed mutability"
)


Expand Down
Loading

0 comments on commit e84c676

Please sign in to comment.