Skip to content
Closed
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
38 changes: 38 additions & 0 deletions binary-leb128.wast
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,41 @@
)
"integer too large"
)


(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; empty function type
"\03\02\01" ;; function section
"\00" ;; function 0, type 0
"\0a\1b\01\19" ;; code section
"\00" ;; no locals
"\00" ;; unreachable
"\fc\80\00" ;; i32_trunc_sat_f32_s with 2 bytes
"\00" ;; unreachable
"\fc\81\80\00" ;; i32_trunc_sat_f32_u with 3 bytes
"\00" ;; unreachable
"\fc\86\80\80\00" ;; i64_trunc_sat_f64_s with 4 bytes
"\00" ;; unreachable
"\fc\87\80\80\80\00" ;; i64_trunc_sat_f64_u with 5 bytes
"\00" ;; unreachable
"\0b" ;; end
)

(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01" ;; type section
"\60\00\00" ;; empty function type
"\03\02\01" ;; function section
"\00" ;; function 0, type 0
"\0a\0d\01\0b" ;; code section
"\00" ;; no locals
"\00" ;; unreachable
"\fc\87\80\80\80\80\00" ;; i64_trunc_sat_f64_u with 6 bytes
"\00" ;; unreachable
"\0b" ;; end
)
"integer representation too long"
)
140 changes: 140 additions & 0 deletions binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
(assert_malformed (module binary "\00asm\00\00\01\00") "unknown binary version")
(assert_malformed (module binary "\00asm\00\00\00\01") "unknown binary version")

;; Invalid section id.
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\0c\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\7f\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\80\00\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\00\01\00") "malformed section id")
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\00\01\00") "malformed section id")


;; call_indirect reserved byte equal to zero.
(assert_malformed
Expand Down Expand Up @@ -450,6 +457,71 @@
"\02\01\00" ;; import count can be zero
)

;; Malformed import kind
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\04" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\04" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\05" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\05" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\04\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\80" ;; malformed import kind
)
"malformed import kind"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\02\05\01" ;; import section with single entry
"\00" ;; string length 0
"\00" ;; string length 0
"\80" ;; malformed import kind
"\00" ;; dummy byte
)
"malformed import kind"
)

;; 2 import declared, 1 given
(assert_malformed
(module binary
Expand Down Expand Up @@ -510,6 +582,37 @@
"unexpected end of section or function"
)

;; Malformed table limits flag
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; table section with one entry
"\70" ;; anyfunc
"\02" ;; malformed table limits flag
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\04\01" ;; table section with one entry
"\70" ;; anyfunc
"\02" ;; malformed table limits flag
"\00" ;; dummy byte
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\06\01" ;; table section with one entry
"\70" ;; anyfunc
"\81\00" ;; malformed table limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer too large"
)

;; Memory count can be zero
(module binary
"\00asm" "\01\00\00\00"
Expand All @@ -526,6 +629,43 @@
"unexpected end of section or function"
)

;; Malformed memory limits flag
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\02\01" ;; memory section with one entry
"\02" ;; malformed memory limits flag
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; memory section with one entry
"\02" ;; malformed memory limits flag
"\00" ;; dummy byte
)
"integer too large"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\05\01" ;; memory section with one entry
"\81\00" ;; malformed memory limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer representation too long"
)
(assert_malformed
(module binary
"\00asm" "\01\00\00\00"
"\05\05\01" ;; memory section with one entry
"\81\01" ;; malformed memory limits flag as LEB128
"\00\00" ;; dummy bytes
)
"integer representation too long"
)

;; Global count can be zero
(module binary
"\00asm" "\01\00\00\00"
Expand Down
40 changes: 40 additions & 0 deletions func.wast
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,46 @@
"unknown type"
)

(assert_malformed
(module quote
"(func $f (result f64) (f64.const 0))" ;; adds implicit type definition
"(func $g (param i32))" ;; reuses explicit type definition
"(func $h (result f64) (f64.const 1))" ;; reuses implicit type definition
"(type $t (func (param i32)))"

"(func (type 2) (param i32))" ;; does not exist
)
"unknown type"
)

(module
(type $proc (func (result i32)))
(type $sig (func (param i32) (result i32)))

(func (export "f") (type $sig)
(local $var i32)
(local.get $var)
)

(func $g (type $sig)
(local $var i32)
(local.get $var)
)
(func (export "g") (type $sig)
(call $g (local.get 0))
)

(func (export "p") (type $proc)
(local $var i32)
(local.set 0 (i32.const 42))
(local.get $var)
)
)

(assert_return (invoke "f" (i32.const 42)) (i32.const 0))
(assert_return (invoke "g" (i32.const 42)) (i32.const 0))
(assert_return (invoke "p") (i32.const 42))


(module
(type $sig (func))
Expand Down
Loading