Skip to content

Commit c559d91

Browse files
rossberggumb0
authored andcommitted
[interpreter] Change error messages to say 'malformed' for binary (WebAssembly#1149)
1 parent f750d21 commit c559d91

9 files changed

+762
-762
lines changed

interpreter/binary/decode.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ let vec f s = let n = len32 s in list f n s
117117
let name s =
118118
let pos = pos s in
119119
try Utf8.decode (string s) with Utf8.Utf8 ->
120-
error s pos "invalid UTF-8 encoding"
120+
error s pos "malformed UTF-8 encoding"
121121

122122
let sized f s =
123123
let size = len32 s in
@@ -137,12 +137,12 @@ let value_type s =
137137
| -0x02 -> I64Type
138138
| -0x03 -> F32Type
139139
| -0x04 -> F64Type
140-
| _ -> error s (pos s - 1) "invalid value type"
140+
| _ -> error s (pos s - 1) "malformed value type"
141141

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

147147
let stack_type s =
148148
match peek s with
@@ -155,7 +155,7 @@ let func_type s =
155155
let ins = vec value_type s in
156156
let out = vec value_type s in
157157
FuncType (ins, out)
158-
| _ -> error s (pos s - 1) "invalid function type"
158+
| _ -> error s (pos s - 1) "malformed function type"
159159

160160
let limits vu s =
161161
let has_max = bool s in
@@ -176,7 +176,7 @@ let mutability s =
176176
match u8 s with
177177
| 0 -> Immutable
178178
| 1 -> Mutable
179-
| _ -> error s (pos s - 1) "invalid mutability"
179+
| _ -> error s (pos s - 1) "malformed mutability"
180180

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

197197
let memop s =
198198
let align = vu32 s in
199-
require (I32.le_u align 32l) s (pos s - 1) "invalid memop flags";
199+
require (I32.le_u align 32l) s (pos s - 1) "malformed memop flags";
200200
let offset = vu32 s in
201201
Int32.to_int align, offset
202202

@@ -467,7 +467,7 @@ let id s =
467467
| 9 -> `ElemSection
468468
| 10 -> `CodeSection
469469
| 11 -> `DataSection
470-
| _ -> error s (pos s) "invalid section id"
470+
| _ -> error s (pos s) "malformed section id"
471471
) bo
472472

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

500500
let import s =
501501
let module_name = name s in
@@ -552,7 +552,7 @@ let export_desc s =
552552
| 0x01 -> TableExport (at var s)
553553
| 0x02 -> MemoryExport (at var s)
554554
| 0x03 -> GlobalExport (at var s)
555-
| _ -> error s (pos s - 1) "invalid export kind"
555+
| _ -> error s (pos s - 1) "malformed export kind"
556556

557557
let export s =
558558
let name = name s in

interpreter/text/parser.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let nat32 s at =
5757
try I32.of_string_u s with Failure _ -> error at "i32 constant out of range"
5858

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

6262

6363
(* Symbolic variables *)

test/core/binary.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@
636636
"\0a\04\01" ;; code section
637637
"\02\00\0b" ;; function body
638638
)
639-
"invalid value type"
639+
"malformed value type"
640640
)
641641

642642
;; 1 elem segment declared, 2 given
@@ -777,7 +777,7 @@
777777
"\02" ;; break depth for default
778778
"\0b\0b\0b" ;; end
779779
)
780-
"invalid value type"
780+
"malformed value type"
781781
)
782782

783783
;; Start section

test/core/custom.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@
9595
"\00\25\10" "a custom section" "this is the payload"
9696
"\00\24\10" "a custom section" "this is the payload"
9797
)
98-
"invalid section id"
98+
"malformed section id"
9999
)
100100

101101
(assert_malformed
102102
(module binary
103103
"\00asm" "\01\00\00\00"
104104
"\01\07\01\60\02\7f\7f\01\7f" ;; type section
105-
"\00\25\10" "a custom section" "this is the payload" ;; invalid length!
105+
"\00\25\10" "a custom section" "this is the payload" ;; wrong length!
106106
"\03\02\01\00" ;; function section
107107
"\0a\09\01\07\00\20\00\20\01\6a\0b" ;; code section
108108
"\00\1b\07" "custom2" "this is the payload" ;; custom section

test/core/global.wast

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@
310310
"\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
311311
"\03" ;; GlobalImport
312312
"\7f" ;; i32
313-
"\02" ;; invalid mutability
313+
"\02" ;; malformed mutability
314314
)
315-
"invalid mutability"
315+
"malformed mutability"
316316
)
317317
(assert_malformed
318318
(module binary
@@ -323,9 +323,9 @@
323323
"\0a\67\6c\6f\62\61\6c\5f\69\33\32" ;; "global_i32"
324324
"\03" ;; GlobalImport
325325
"\7f" ;; i32
326-
"\ff" ;; invalid mutability
326+
"\ff" ;; malformed mutability
327327
)
328-
"invalid mutability"
328+
"malformed mutability"
329329
)
330330

331331
(module
@@ -337,23 +337,23 @@
337337
"\06\86\80\80\80\00" ;; global section
338338
"\01" ;; length 1
339339
"\7f" ;; i32
340-
"\02" ;; invalid mutability
340+
"\02" ;; malformed mutability
341341
"\41\00" ;; i32.const 0
342342
"\0b" ;; end
343343
)
344-
"invalid mutability"
344+
"malformed mutability"
345345
)
346346
(assert_malformed
347347
(module binary
348348
"\00asm" "\01\00\00\00"
349349
"\06\86\80\80\80\00" ;; global section
350350
"\01" ;; length 1
351351
"\7f" ;; i32
352-
"\ff" ;; invalid mutability
352+
"\ff" ;; malformed mutability
353353
"\41\00" ;; i32.const 0
354354
"\0b" ;; end
355355
)
356-
"invalid mutability"
356+
"malformed mutability"
357357
)
358358

359359

0 commit comments

Comments
 (0)