...

Text file src/github.com/tetratelabs/wazero/internal/integration_test/spectest/v2/testdata/binary.wast

Documentation: github.com/tetratelabs/wazero/internal/integration_test/spectest/v2/testdata

     1(module binary "\00asm\01\00\00\00")
     2(module binary "\00asm" "\01\00\00\00")
     3(module $M1 binary "\00asm\01\00\00\00")
     4(module $M2 binary "\00asm" "\01\00\00\00")
     5
     6(assert_malformed (module binary "") "unexpected end")
     7(assert_malformed (module binary "\01") "unexpected end")
     8(assert_malformed (module binary "\00as") "unexpected end")
     9(assert_malformed (module binary "asm\00") "magic header not detected")
    10(assert_malformed (module binary "msa\00") "magic header not detected")
    11(assert_malformed (module binary "msa\00\01\00\00\00") "magic header not detected")
    12(assert_malformed (module binary "msa\00\00\00\00\01") "magic header not detected")
    13(assert_malformed (module binary "asm\01\00\00\00\00") "magic header not detected")
    14(assert_malformed (module binary "wasm\01\00\00\00") "magic header not detected")
    15(assert_malformed (module binary "\7fasm\01\00\00\00") "magic header not detected")
    16(assert_malformed (module binary "\80asm\01\00\00\00") "magic header not detected")
    17(assert_malformed (module binary "\82asm\01\00\00\00") "magic header not detected")
    18(assert_malformed (module binary "\ffasm\01\00\00\00") "magic header not detected")
    19
    20;; 8-byte endian-reversed.
    21(assert_malformed (module binary "\00\00\00\01msa\00") "magic header not detected")
    22
    23;; Middle-endian byte orderings.
    24(assert_malformed (module binary "a\00ms\00\01\00\00") "magic header not detected")
    25(assert_malformed (module binary "sm\00a\00\00\01\00") "magic header not detected")
    26
    27;; Upper-cased.
    28(assert_malformed (module binary "\00ASM\01\00\00\00") "magic header not detected")
    29
    30;; EBCDIC-encoded magic.
    31(assert_malformed (module binary "\00\81\a2\94\01\00\00\00") "magic header not detected")
    32
    33;; Leading UTF-8 BOM.
    34(assert_malformed (module binary "\ef\bb\bf\00asm\01\00\00\00") "magic header not detected")
    35
    36;; Malformed binary version.
    37(assert_malformed (module binary "\00asm") "unexpected end")
    38(assert_malformed (module binary "\00asm\01") "unexpected end")
    39(assert_malformed (module binary "\00asm\01\00\00") "unexpected end")
    40(assert_malformed (module binary "\00asm\00\00\00\00") "unknown binary version")
    41(assert_malformed (module binary "\00asm\0d\00\00\00") "unknown binary version")
    42(assert_malformed (module binary "\00asm\0e\00\00\00") "unknown binary version")
    43(assert_malformed (module binary "\00asm\00\01\00\00") "unknown binary version")
    44(assert_malformed (module binary "\00asm\00\00\01\00") "unknown binary version")
    45(assert_malformed (module binary "\00asm\00\00\00\01") "unknown binary version")
    46
    47;; Invalid section id.
    48(assert_malformed (module binary "\00asm" "\01\00\00\00" "\0e\01\00") "malformed section id")
    49(assert_malformed (module binary "\00asm" "\01\00\00\00" "\7f\01\00") "malformed section id")
    50(assert_malformed (module binary "\00asm" "\01\00\00\00" "\80\01\00\01\01\00") "malformed section id")
    51(assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\01\00\01\01\00") "malformed section id")
    52(assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\01\00\01\01\00") "malformed section id")
    53
    54;; Function with missing end marker (between two functions)
    55(assert_malformed
    56  (module binary
    57    "\00asm" "\01\00\00\00"
    58    "\01\04\01\60\00\00"       ;; Type section: 1 type
    59    "\03\03\02\00\00"          ;; Function section: 2 functions
    60    "\0a\0c\02"                ;; Code section: 2 functions
    61    ;; function 0
    62    "\04\00"                   ;; Function size and local type count
    63    "\41\01"                   ;; i32.const 1
    64    "\1a"                      ;; drop
    65    ;; Missing end marker here
    66    ;; function 1
    67    "\05\00"                   ;; Function size and local type count
    68    "\41\01"                   ;; i32.const 1
    69    "\1a"                      ;; drop
    70    "\0b"                      ;; end
    71  )
    72  "END opcode expected"
    73)
    74
    75;; Function with missing end marker (at EOF)
    76(assert_malformed
    77  (module binary
    78    "\00asm" "\01\00\00\00"
    79    "\01\04\01\60\00\00"       ;; Type section: 1 type
    80    "\03\02\01\00"             ;; Function section: 1 function
    81    "\0a\06\01"                ;; Code section: 1 function
    82    ;; function 0
    83    "\04\00"                   ;; Function size and local type count
    84    "\41\01"                   ;; i32.const 1
    85    "\1a"                      ;; drop
    86    ;; Missing end marker here
    87  )
    88  "unexpected end of section or function"
    89)
    90
    91;; Function with missing end marker (at end of code sections)
    92(assert_malformed
    93  (module binary
    94    "\00asm" "\01\00\00\00"
    95    "\01\04\01\60\00\00"       ;; Type section: 1 type
    96    "\03\02\01\00"             ;; Function section: 1 function
    97    "\0a\06\01"                ;; Code section: 1 function
    98    ;; function 0
    99    "\04\00"                   ;; Function size and local type count
   100    "\41\01"                   ;; i32.const 1
   101    "\1a"                      ;; drop
   102    ;; Missing end marker here
   103    "\0b\03\01\01\00"          ;; Data section
   104  )
   105  ;; The spec interpreter consumes the `\0b` (data section start) as an
   106  ;; END instruction (also happens to be `\0b`) and reports the code section as
   107  ;; being larger than declared.
   108  "section size mismatch"
   109)
   110
   111;; Init expression with missing end marker
   112(assert_malformed
   113  (module binary
   114    "\00asm" "\01\00\00\00"
   115    "\01\04\01\60\00\00"       ;; Type section: 1 type
   116    "\03\02\01\00"             ;; Function section: 1 function
   117    "\06\05\01\7f\00\41\00"    ;; Global section: 1 entry with missing end marker
   118    ;; Missing end marker here
   119    "\0a\04\01\02\00\0b"       ;; Code section: 1 function
   120  )
   121  "illegal opcode"
   122)
   123
   124;; memory.grow reserved byte equal to zero.
   125(assert_malformed
   126  (module binary
   127    "\00asm" "\01\00\00\00"
   128    "\01\04\01\60\00\00"       ;; Type section
   129    "\03\02\01\00"             ;; Function section
   130    "\05\03\01\00\00"          ;; Memory section
   131    "\0a\09\01"                ;; Code section
   132
   133    ;; function 0
   134    "\07\00"
   135    "\41\00"                   ;; i32.const 0
   136    "\40"                      ;; memory.grow
   137    "\01"                      ;; memory.grow reserved byte is not equal to zero!
   138    "\1a"                      ;; drop
   139    "\0b"                      ;; end
   140  )
   141  "zero byte expected"
   142)
   143
   144;; memory.grow reserved byte should not be a "long" LEB128 zero.
   145(assert_malformed
   146  (module binary
   147    "\00asm" "\01\00\00\00"
   148    "\01\04\01\60\00\00"       ;; Type section
   149    "\03\02\01\00"             ;; Function section
   150    "\05\03\01\00\00"          ;; Memory section
   151    "\0a\0a\01"                ;; Code section
   152
   153    ;; function 0
   154    "\08\00"
   155    "\41\00"                   ;; i32.const 0
   156    "\40"                      ;; memory.grow
   157    "\80\00"                   ;; memory.grow reserved byte
   158    "\1a"                      ;; drop
   159    "\0b"                      ;; end
   160  )
   161  "zero byte expected"
   162)
   163
   164;; Same as above for 3, 4, and 5-byte zero encodings.
   165(assert_malformed
   166  (module binary
   167    "\00asm" "\01\00\00\00"
   168    "\01\04\01\60\00\00"       ;; Type section
   169    "\03\02\01\00"             ;; Function section
   170    "\05\03\01\00\00"          ;; Memory section
   171    "\0a\0b\01"                ;; Code section
   172
   173    ;; function 0
   174    "\09\00"
   175    "\41\00"                   ;; i32.const 0
   176    "\40"                      ;; memory.grow
   177    "\80\80\00"                ;; memory.grow reserved byte
   178    "\1a"                      ;; drop
   179    "\0b"                      ;; end
   180  )
   181  "zero byte expected"
   182)
   183
   184(assert_malformed
   185  (module binary
   186    "\00asm" "\01\00\00\00"
   187    "\01\04\01\60\00\00"       ;; Type section
   188    "\03\02\01\00"             ;; Function section
   189    "\05\03\01\00\00"          ;; Memory section
   190    "\0a\0c\01"                ;; Code section
   191
   192    ;; function 0
   193    "\0a\00"
   194    "\41\00"                   ;; i32.const 0
   195    "\40"                      ;; memory.grow
   196    "\80\80\80\00"             ;; memory.grow reserved byte
   197    "\1a"                      ;; drop
   198    "\0b"                      ;; end
   199  )
   200  "zero byte expected"
   201)
   202
   203(assert_malformed
   204  (module binary
   205    "\00asm" "\01\00\00\00"
   206    "\01\04\01\60\00\00"       ;; Type section
   207    "\03\02\01\00"             ;; Function section
   208    "\05\03\01\00\00"          ;; Memory section
   209    "\0a\0d\01"                ;; Code section
   210
   211    ;; function 0
   212    "\0b\00"
   213    "\41\00"                   ;; i32.const 0
   214    "\40"                      ;; memory.grow
   215    "\80\80\80\80\00"          ;; memory.grow reserved byte
   216    "\1a"                      ;; drop
   217    "\0b"                      ;; end
   218  )
   219  "zero byte expected"
   220)
   221
   222;; memory.size reserved byte equal to zero.
   223(assert_malformed
   224  (module binary
   225    "\00asm" "\01\00\00\00"
   226    "\01\04\01\60\00\00"       ;; Type section
   227    "\03\02\01\00"             ;; Function section
   228    "\05\03\01\00\00"          ;; Memory section
   229    "\0a\07\01"                ;; Code section
   230
   231    ;; function 0
   232    "\05\00"
   233    "\3f"                      ;; memory.size
   234    "\01"                      ;; memory.size reserved byte is not equal to zero!
   235    "\1a"                      ;; drop
   236    "\0b"                      ;; end
   237  )
   238  "zero byte expected"
   239)
   240
   241;; memory.size reserved byte should not be a "long" LEB128 zero.
   242(assert_malformed
   243  (module binary
   244    "\00asm" "\01\00\00\00"
   245    "\01\04\01\60\00\00"       ;; Type section
   246    "\03\02\01\00"             ;; Function section
   247    "\05\03\01\00\00"          ;; Memory section
   248    "\0a\08\01"                ;; Code section
   249
   250    ;; function 0
   251    "\06\00"
   252    "\3f"                      ;; memory.size
   253    "\80\00"                   ;; memory.size reserved byte
   254    "\1a"                      ;; drop
   255    "\0b"                      ;; end
   256  )
   257  "zero byte expected"
   258)
   259
   260;; Same as above for 3, 4, and 5-byte zero encodings.
   261(assert_malformed
   262  (module binary
   263    "\00asm" "\01\00\00\00"
   264    "\01\04\01\60\00\00"       ;; Type section
   265    "\03\02\01\00"             ;; Function section
   266    "\05\03\01\00\00"          ;; Memory section
   267    "\0a\09\01"                ;; Code section
   268
   269    ;; function 0
   270    "\07\00"
   271    "\3f"                      ;; memory.size
   272    "\80\80\00"                ;; memory.size reserved byte
   273    "\1a"                      ;; drop
   274    "\0b"                      ;; end
   275  )
   276  "zero byte expected"
   277)
   278
   279(assert_malformed
   280  (module binary
   281    "\00asm" "\01\00\00\00"
   282    "\01\04\01\60\00\00"       ;; Type section
   283    "\03\02\01\00"             ;; Function section
   284    "\05\03\01\00\00"          ;; Memory section
   285    "\0a\0a\01"                ;; Code section
   286
   287    ;; function 0
   288    "\08\00"
   289    "\3f"                      ;; memory.size
   290    "\80\80\80\00"             ;; memory.size reserved byte
   291    "\1a"                      ;; drop
   292    "\0b"                      ;; end
   293  )
   294  "zero byte expected"
   295)
   296
   297(assert_malformed
   298  (module binary
   299    "\00asm" "\01\00\00\00"
   300    "\01\04\01\60\00\00"       ;; Type section
   301    "\03\02\01\00"             ;; Function section
   302    "\05\03\01\00\00"          ;; Memory section
   303    "\0a\0b\01"                ;; Code section
   304
   305    ;; function 0
   306    "\09\00"
   307    "\3f"                      ;; memory.size
   308    "\80\80\80\80\00"          ;; memory.size reserved byte
   309    "\1a"                      ;; drop
   310    "\0b"                      ;; end
   311  )
   312  "zero byte expected"
   313)
   314
   315;; Local number is unsigned 32 bit
   316(assert_malformed
   317  (module binary
   318    "\00asm" "\01\00\00\00"
   319    "\01\04\01\60\00\00"       ;; Type section
   320    "\03\02\01\00"             ;; Function section
   321    "\0a\0c\01"                ;; Code section
   322
   323    ;; function 0
   324    "\0a\02"
   325    "\80\80\80\80\10\7f"       ;; 0x100000000 i32
   326    "\02\7e"                   ;; 0x00000002 i64
   327    "\0b"                      ;; end
   328  )
   329  "integer too large"
   330)
   331
   332;; Local number is unsigned 32 bit
   333(assert_malformed
   334  (module binary
   335    "\00asm" "\01\00\00\00"
   336    "\01\04\01\60\00\00"       ;; Type section
   337    "\03\02\01\00"             ;; Function section
   338    "\0a\0c\01"                ;; Code section
   339
   340    ;; function 0
   341    "\0a\02"
   342    "\80\80\80\80\10\7f"       ;; 0x100000000 i32
   343    "\02\7e"                   ;; 0x00000002 i64
   344    "\0b"                      ;; end
   345  )
   346  "integer too large"
   347)
   348
   349;; No more than 2^32-1 locals.
   350(assert_malformed
   351  (module binary
   352    "\00asm" "\01\00\00\00"
   353    "\01\04\01\60\00\00"       ;; Type section
   354    "\03\02\01\00"             ;; Function section
   355    "\0a\0c\01"                ;; Code section
   356
   357    ;; function 0
   358    "\0a\02"
   359    "\ff\ff\ff\ff\0f\7f"       ;; 0xFFFFFFFF i32
   360    "\02\7e"                   ;; 0x00000002 i64
   361    "\0b"                      ;; end
   362  )
   363  "too many locals"
   364)
   365
   366(assert_malformed
   367  (module binary
   368    "\00asm" "\01\00\00\00"
   369    "\01\06\01\60\02\7f\7f\00" ;; Type section: (param i32 i32)
   370    "\03\02\01\00"             ;; Function section
   371    "\0a\1c\01"                ;; Code section
   372
   373    ;; function 0
   374    "\1a\04"
   375    "\80\80\80\80\04\7f"       ;; 0x40000000 i32
   376    "\80\80\80\80\04\7e"       ;; 0x40000000 i64
   377    "\80\80\80\80\04\7d"       ;; 0x40000000 f32
   378    "\80\80\80\80\04\7c"       ;; 0x40000000 f64
   379    "\0b"                      ;; end
   380  )
   381  "too many locals"
   382)
   383
   384;; Local count can be 0.
   385(module binary
   386  "\00asm" "\01\00\00\00"
   387  "\01\04\01\60\00\00"     ;; Type section
   388  "\03\02\01\00"           ;; Function section
   389  "\0a\0a\01"              ;; Code section
   390
   391  ;; function 0
   392  "\08\03"
   393  "\00\7f"                 ;; 0 i32
   394  "\00\7e"                 ;; 0 i64
   395  "\02\7d"                 ;; 2 f32
   396  "\0b"                    ;; end
   397)
   398
   399;; Function section has non-zero count, but code section is absent.
   400(assert_malformed
   401  (module binary
   402    "\00asm" "\01\00\00\00"
   403    "\01\04\01\60\00\00"  ;; Type section
   404    "\03\03\02\00\00"     ;; Function section with 2 functions
   405  )
   406  "function and code section have inconsistent lengths"
   407)
   408
   409;; Code section has non-zero count, but function section is absent.
   410(assert_malformed
   411  (module binary
   412    "\00asm" "\01\00\00\00"
   413    "\0a\04\01\02\00\0b"  ;; Code section with 1 empty function
   414  )
   415  "function and code section have inconsistent lengths"
   416)
   417
   418;; Function section count > code section count
   419(assert_malformed
   420  (module binary
   421    "\00asm" "\01\00\00\00"
   422    "\01\04\01\60\00\00"  ;; Type section
   423    "\03\03\02\00\00"     ;; Function section with 2 functions
   424    "\0a\04\01\02\00\0b"  ;; Code section with 1 empty function
   425  )
   426  "function and code section have inconsistent lengths"
   427)
   428
   429;; Function section count < code section count
   430(assert_malformed
   431  (module binary
   432    "\00asm" "\01\00\00\00"
   433    "\01\04\01\60\00\00"           ;; Type section
   434    "\03\02\01\00"                 ;; Function section with 1 function
   435    "\0a\07\02\02\00\0b\02\00\0b"  ;; Code section with 2 empty functions
   436  )
   437  "function and code section have inconsistent lengths"
   438)
   439
   440;; Function section has zero count, and code section is absent.
   441(module binary
   442  "\00asm" "\01\00\00\00"
   443  "\03\01\00"  ;; Function section with 0 functions
   444)
   445
   446;; Code section has zero count, and function section is absent.
   447(module binary
   448  "\00asm" "\01\00\00\00"
   449  "\0a\01\00"  ;; Code section with 0 functions
   450)
   451
   452;; Fewer passive segments than datacount
   453(assert_malformed
   454  (module binary
   455    "\00asm" "\01\00\00\00"
   456    "\0c\01\03"                   ;; Datacount section with value "3"
   457    "\0b\05\02"                   ;; Data section with two entries
   458    "\01\00"                      ;; Passive data section
   459    "\01\00")                     ;; Passive data section
   460  "data count and data section have inconsistent lengths")
   461
   462;; More passive segments than datacount
   463(assert_malformed
   464  (module binary
   465    "\00asm" "\01\00\00\00"
   466    "\0c\01\01"                   ;; Datacount section with value "1"
   467    "\0b\05\02"                   ;; Data section with two entries
   468    "\01\00"                      ;; Passive data section
   469    "\01\00")                     ;; Passive data section
   470  "data count and data section have inconsistent lengths")
   471
   472;; memory.init requires a datacount section
   473(assert_malformed
   474  (module binary
   475    "\00asm" "\01\00\00\00"
   476
   477    "\01\04\01\60\00\00"       ;; Type section
   478    "\03\02\01\00"             ;; Function section
   479    "\05\03\01\00\00"          ;; Memory section
   480    "\0a\0e\01"                ;; Code section
   481
   482    ;; function 0
   483    "\0c\00"
   484    "\41\00"                   ;; zero args
   485    "\41\00"
   486    "\41\00"
   487    "\fc\08\00\00"             ;; memory.init
   488    "\0b"
   489
   490    "\0b\03\01\01\00"          ;; Data section
   491  )                            ;; end
   492  "data count section required")
   493
   494;; data.drop requires a datacount section
   495(assert_malformed
   496  (module binary
   497    "\00asm" "\01\00\00\00"
   498
   499    "\01\04\01\60\00\00"       ;; Type section
   500    "\03\02\01\00"             ;; Function section
   501    "\05\03\01\00\00"          ;; Memory section
   502    "\0a\07\01"                ;; Code section
   503
   504    ;; function 0
   505    "\05\00"
   506    "\fc\09\00"                ;; data.drop
   507    "\0b"
   508
   509    "\0b\03\01\01\00"          ;; Data section
   510  )                            ;; end
   511  "data count section required")
   512
   513;; passive element segment containing illegal opcode
   514(assert_malformed
   515  (module binary
   516    "\00asm" "\01\00\00\00"
   517
   518    "\01\04\01\60\00\00"       ;; Type section
   519
   520    "\03\02\01\00"             ;; Function section
   521
   522    "\04\04\01"                ;; Table section with 1 entry
   523    "\70\00\00"                ;; no max, minimum 0, funcref
   524
   525    "\05\03\01\00\00"          ;; Memory section
   526
   527    "\09\07\01"                ;; Element section with one segment
   528    "\05\70"                   ;; Passive, funcref
   529    "\01"                      ;; 1 element
   530    "\f3\00\0b"                ;; bad opcode, index 0, end
   531
   532    "\0a\04\01"                ;; Code section
   533
   534    ;; function 0
   535    "\02\00"
   536    "\0b")                     ;; end
   537  "illegal opcode")
   538
   539;; passive element segment containing type other than funcref
   540(assert_malformed
   541  (module binary
   542    "\00asm" "\01\00\00\00"
   543
   544    "\01\04\01\60\00\00"       ;; Type section
   545
   546    "\03\02\01\00"             ;; Function section
   547
   548    "\04\04\01"                ;; Table section with 1 entry
   549    "\70\00\00"                ;; no max, minimum 0, funcref
   550
   551    "\05\03\01\00\00"          ;; Memory section
   552
   553    "\09\07\01"                ;; Element section with one segment
   554    "\05\7f"                   ;; Passive, i32
   555    "\01"                      ;; 1 element
   556    "\d2\00\0b"                ;; ref.func, index 0, end
   557
   558    "\0a\04\01"                ;; Code section
   559
   560    ;; function 0
   561    "\02\00"
   562    "\0b")                     ;; end
   563  "malformed reference type")
   564
   565;; passive element segment containing opcode ref.func
   566(module binary
   567  "\00asm" "\01\00\00\00"
   568
   569  "\01\04\01\60\00\00"       ;; Type section
   570
   571  "\03\02\01\00"             ;; Function section
   572
   573  "\04\04\01"                ;; Table section with 1 entry
   574  "\70\00\00"                ;; no max, minimum 0, funcref
   575
   576  "\05\03\01\00\00"          ;; Memory section
   577
   578  "\09\07\01"                ;; Element section with one segment
   579  "\05\70"                   ;; Passive, funcref
   580  "\01"                      ;; 1 element
   581  "\d2\00\0b"                ;; ref.func, index 0, end
   582
   583  "\0a\04\01"                ;; Code section
   584
   585  ;; function 0
   586  "\02\00"
   587  "\0b")                     ;; end
   588
   589;; passive element segment containing opcode ref.null
   590(module binary
   591  "\00asm" "\01\00\00\00"
   592
   593  "\01\04\01\60\00\00"       ;; Type section
   594
   595  "\03\02\01\00"             ;; Function section
   596
   597  "\04\04\01"                ;; Table section with 1 entry
   598  "\70\00\00"                ;; no max, minimum 0, funcref
   599
   600  "\05\03\01\00\00"          ;; Memory section
   601
   602  "\09\07\01"                ;; Element section with one segment
   603  "\05\70"                   ;; Passive, funcref
   604  "\01"                      ;; 1 element
   605  "\d0\70\0b"                ;; ref.null, end
   606
   607  "\0a\04\01"                ;; Code section
   608
   609  ;; function 0
   610  "\02\00"
   611  "\0b")                     ;; end
   612
   613
   614;; Type count can be zero
   615(module binary
   616  "\00asm" "\01\00\00\00"
   617  "\01\01\00"                               ;; type count can be zero
   618)
   619
   620;; 2 type declared, 1 given
   621(assert_malformed
   622  (module binary
   623    "\00asm" "\01\00\00\00"
   624    "\01\07\02"                             ;; type section with inconsistent count (2 declared, 1 given)
   625    "\60\00\00"                             ;; 1st type
   626    ;; "\60\00\00"                          ;; 2nd type (missed)
   627  )
   628  "length out of bounds"
   629)
   630
   631;; 1 type declared, 2 given
   632(assert_malformed
   633  (module binary
   634    "\00asm" "\01\00\00\00"
   635    "\01\07\01"                             ;; type section with inconsistent count (1 declared, 2 given)
   636    "\60\00\00"                             ;; 1st type
   637    "\60\00\00"                             ;; 2nd type (redundant)
   638  )
   639  "section size mismatch"
   640)
   641
   642;; Import count can be zero
   643(module binary
   644    "\00asm" "\01\00\00\00"
   645    "\01\05\01"                             ;; type section
   646    "\60\01\7f\00"                          ;; type 0
   647    "\02\01\00"                             ;; import count can be zero
   648)
   649
   650;; Malformed import kind
   651(assert_malformed
   652  (module binary
   653      "\00asm" "\01\00\00\00"
   654      "\02\04\01"                           ;; import section with single entry
   655      "\00"                                 ;; string length 0
   656      "\00"                                 ;; string length 0
   657      "\04"                                 ;; malformed import kind
   658  )
   659  "malformed import kind"
   660)
   661(assert_malformed
   662  (module binary
   663      "\00asm" "\01\00\00\00"
   664      "\02\05\01"                           ;; import section with single entry
   665      "\00"                                 ;; string length 0
   666      "\00"                                 ;; string length 0
   667      "\04"                                 ;; malformed import kind
   668      "\00"                                 ;; dummy byte
   669  )
   670  "malformed import kind"
   671)
   672(assert_malformed
   673  (module binary
   674      "\00asm" "\01\00\00\00"
   675      "\02\04\01"                           ;; import section with single entry
   676      "\00"                                 ;; string length 0
   677      "\00"                                 ;; string length 0
   678      "\05"                                 ;; malformed import kind
   679  )
   680  "malformed import kind"
   681)
   682(assert_malformed
   683  (module binary
   684      "\00asm" "\01\00\00\00"
   685      "\02\05\01"                           ;; import section with single entry
   686      "\00"                                 ;; string length 0
   687      "\00"                                 ;; string length 0
   688      "\05"                                 ;; malformed import kind
   689      "\00"                                 ;; dummy byte
   690  )
   691  "malformed import kind"
   692)
   693(assert_malformed
   694  (module binary
   695      "\00asm" "\01\00\00\00"
   696      "\02\04\01"                           ;; import section with single entry
   697      "\00"                                 ;; string length 0
   698      "\00"                                 ;; string length 0
   699      "\80"                                 ;; malformed import kind
   700  )
   701  "malformed import kind"
   702)
   703(assert_malformed
   704  (module binary
   705      "\00asm" "\01\00\00\00"
   706      "\02\05\01"                           ;; import section with single entry
   707      "\00"                                 ;; string length 0
   708      "\00"                                 ;; string length 0
   709      "\80"                                 ;; malformed import kind
   710      "\00"                                 ;; dummy byte
   711  )
   712  "malformed import kind"
   713)
   714
   715;; 2 import declared, 1 given
   716(assert_malformed
   717  (module binary
   718      "\00asm" "\01\00\00\00"
   719      "\01\05\01"                           ;; type section
   720      "\60\01\7f\00"                        ;; type 0
   721      "\02\16\02"                           ;; import section with inconsistent count (2 declared, 1 given)
   722      ;; 1st import
   723      "\08"                                 ;; string length
   724      "\73\70\65\63\74\65\73\74"            ;; spectest
   725      "\09"                                 ;; string length
   726      "\70\72\69\6e\74\5f\69\33\32"         ;; print_i32
   727      "\00\00"                              ;; import kind, import signature index
   728      ;; 2nd import
   729      ;; (missed)
   730  )
   731  "unexpected end of section or function"
   732)
   733
   734;; 1 import declared, 2 given
   735(assert_malformed
   736  (module binary
   737      "\00asm" "\01\00\00\00"
   738      "\01\09\02"                           ;; type section
   739      "\60\01\7f\00"                        ;; type 0
   740      "\60\01\7d\00"                        ;; type 1
   741      "\02\2b\01"                           ;; import section with inconsistent count (1 declared, 2 given)
   742      ;; 1st import
   743      "\08"                                 ;; string length
   744      "\73\70\65\63\74\65\73\74"            ;; spectest
   745      "\09"                                 ;; string length
   746      "\70\72\69\6e\74\5f\69\33\32"         ;; print_i32
   747      "\00\00"                              ;; import kind, import signature index
   748      ;; 2nd import
   749      ;; (redundant)
   750      "\08"                                 ;; string length
   751      "\73\70\65\63\74\65\73\74"            ;; spectest
   752      "\09"                                 ;; string length
   753      "\70\72\69\6e\74\5f\66\33\32"         ;; print_f32
   754      "\00\01"                              ;; import kind, import signature index
   755  )
   756  "section size mismatch"
   757)
   758
   759;; Table count can be zero
   760(module binary
   761    "\00asm" "\01\00\00\00"
   762    "\04\01\00"                             ;; table count can be zero
   763)
   764
   765;; 1 table declared, 0 given
   766(assert_malformed
   767  (module binary
   768      "\00asm" "\01\00\00\00"
   769      "\04\01\01"                           ;; table section with inconsistent count (1 declared, 0 given)
   770      ;; "\70\01\00\00"                     ;; table entity
   771  )
   772  "unexpected end of section or function"
   773)
   774
   775;; Malformed table limits flag
   776(assert_malformed
   777  (module binary
   778      "\00asm" "\01\00\00\00"
   779      "\04\03\01"                           ;; table section with one entry
   780      "\70"                                 ;; anyfunc
   781      "\02"                                 ;; malformed table limits flag
   782  )
   783  "integer too large"
   784)
   785(assert_malformed
   786  (module binary
   787      "\00asm" "\01\00\00\00"
   788      "\04\04\01"                           ;; table section with one entry
   789      "\70"                                 ;; anyfunc
   790      "\02"                                 ;; malformed table limits flag
   791      "\00"                                 ;; dummy byte
   792  )
   793  "integer too large"
   794)
   795(assert_malformed
   796  (module binary
   797      "\00asm" "\01\00\00\00"
   798      "\04\06\01"                           ;; table section with one entry
   799      "\70"                                 ;; anyfunc
   800      "\81\00"                              ;; malformed table limits flag as LEB128
   801      "\00\00"                              ;; dummy bytes
   802  )
   803  "integer representation too long"
   804)
   805
   806;; Memory count can be zero
   807(module binary
   808    "\00asm" "\01\00\00\00"
   809    "\05\01\00"                             ;; memory count can be zero
   810)
   811
   812;; 1 memory declared, 0 given
   813(assert_malformed
   814  (module binary
   815      "\00asm" "\01\00\00\00"
   816      "\05\01\01"                           ;; memory section with inconsistent count (1 declared, 0 given)
   817      ;; "\00\00"                           ;; memory 0 (missed)
   818  )
   819  "unexpected end of section or function"
   820)
   821
   822;; Malformed memory limits flag
   823(assert_malformed
   824  (module binary
   825      "\00asm" "\01\00\00\00"
   826      "\05\02\01"                           ;; memory section with one entry
   827      "\02"                                 ;; malformed memory limits flag
   828  )
   829  "integer too large"
   830)
   831(assert_malformed
   832  (module binary
   833      "\00asm" "\01\00\00\00"
   834      "\05\03\01"                           ;; memory section with one entry
   835      "\02"                                 ;; malformed memory limits flag
   836      "\00"                                 ;; dummy byte
   837  )
   838  "integer too large"
   839)
   840(assert_malformed
   841  (module binary
   842      "\00asm" "\01\00\00\00"
   843      "\05\05\01"                           ;; memory section with one entry
   844      "\81\00"                              ;; malformed memory limits flag as LEB128
   845      "\00\00"                              ;; dummy bytes
   846  )
   847  "integer representation too long"
   848)
   849(assert_malformed
   850  (module binary
   851      "\00asm" "\01\00\00\00"
   852      "\05\05\01"                           ;; memory section with one entry
   853      "\81\01"                              ;; malformed memory limits flag as LEB128
   854      "\00\00"                              ;; dummy bytes
   855  )
   856  "integer representation too long"
   857)
   858
   859;; Global count can be zero
   860(module binary
   861  "\00asm" "\01\00\00\00"
   862  "\06\01\00"                               ;; global count can be zero
   863)
   864
   865;; 2 global declared, 1 given
   866(assert_malformed
   867  (module binary
   868    "\00asm" "\01\00\00\00"
   869    "\06\06\02"                             ;; global section with inconsistent count (2 declared, 1 given)
   870    "\7f\00\41\00\0b"                       ;; global 0
   871    ;; "\7f\00\41\00\0b"                    ;; global 1 (missed)
   872  )
   873  "unexpected end of section or function"
   874)
   875
   876;; 1 global declared, 2 given
   877(assert_malformed
   878  (module binary
   879    "\00asm" "\01\00\00\00"
   880    "\06\0b\01"                             ;; global section with inconsistent count (1 declared, 2 given)
   881    "\7f\00\41\00\0b"                       ;; global 0
   882    "\7f\00\41\00\0b"                       ;; global 1 (redundant)
   883  )
   884  "section size mismatch"
   885)
   886
   887;; Export count can be 0
   888(module binary
   889  "\00asm" "\01\00\00\00"
   890  "\01\04\01"                               ;; type section
   891  "\60\00\00"                               ;; type 0
   892  "\03\03\02\00\00"                         ;; func section
   893  "\07\01\00"                               ;; export count can be zero
   894  "\0a\07\02"                               ;; code section
   895  "\02\00\0b"                               ;; function body 0
   896  "\02\00\0b"                               ;; function body 1
   897)
   898
   899;; 2 export declared, 1 given
   900(assert_malformed
   901  (module binary
   902    "\00asm" "\01\00\00\00"
   903    "\01\04\01"                             ;; type section
   904    "\60\00\00"                             ;; type 0
   905    "\03\03\02\00\00"                       ;; func section
   906    "\07\06\02"                             ;; export section with inconsistent count (2 declared, 1 given)
   907    "\02"                                   ;; export 0
   908    "\66\31"                                ;; export name
   909    "\00\00"                                ;; export kind, export func index
   910    ;; "\02"                                ;; export 1 (missed)
   911    ;; "\66\32"                             ;; export name
   912    ;; "\00\01"                             ;; export kind, export func index
   913    "\0a\07\02"                             ;; code section
   914    "\02\00\0b"                             ;; function body 0
   915    "\02\00\0b"                             ;; function body 1
   916  )
   917  "length out of bounds"
   918)
   919
   920;; 1 export declared, 2 given
   921(assert_malformed
   922  (module binary
   923    "\00asm" "\01\00\00\00"
   924    "\01\04\01"                             ;; type section
   925    "\60\00\00"                             ;; type 0
   926    "\03\03\02\00\00"                       ;; func section
   927    "\07\0b\01"                             ;; export section with inconsistent count (1 declared, 2 given)
   928    "\02"                                   ;; export 0
   929    "\66\31"                                ;; export name
   930    "\00\00"                                ;; export kind, export func index
   931    "\02"                                   ;; export 1 (redundant)
   932    "\66\32"                                ;; export name
   933    "\00\01"                                ;; export kind, export func index
   934    "\0a\07\02"                             ;; code section
   935    "\02\00\0b"                             ;; function body 0
   936    "\02\00\0b"                             ;; function body 1
   937  )
   938  "section size mismatch"
   939)
   940
   941;; elem segment count can be zero
   942(module binary
   943  "\00asm" "\01\00\00\00"
   944  "\01\04\01"                               ;; type section
   945  "\60\00\00"                               ;; type 0
   946  "\03\02\01\00"                            ;; func section
   947  "\04\04\01"                               ;; table section
   948  "\70\00\01"                               ;; table 0
   949  "\09\01\00"                               ;; elem segment count can be zero
   950  "\0a\04\01"                               ;; code section
   951  "\02\00\0b"                               ;; function body
   952)
   953
   954;; 2 elem segment declared, 1 given
   955(assert_malformed
   956  (module binary
   957    "\00asm" "\01\00\00\00"
   958    "\01\04\01"                             ;; type section
   959    "\60\00\00"                             ;; type 0
   960    "\03\02\01\00"                          ;; func section
   961    "\04\04\01"                             ;; table section
   962    "\70\00\01"                             ;; table 0
   963    "\09\07\02"                             ;; elem with inconsistent segment count (2 declared, 1 given)
   964    "\00\41\00\0b\01\00"                    ;; elem 0
   965    ;; "\00\41\00\0b\01\00"                 ;; elem 1 (missed)
   966  )
   967  "unexpected end"
   968)
   969
   970;; 2 elem segment declared, 1.5 given
   971(assert_malformed
   972  (module binary
   973    "\00asm" "\01\00\00\00"
   974    "\01\04\01"                             ;; type section
   975    "\60\00\00"                             ;; type 0
   976    "\03\02\01\00"                          ;; func section
   977    "\04\04\01"                             ;; table section
   978    "\70\00\01"                             ;; table 0
   979    "\09\0a\02"                             ;; elem with inconsistent segment count (2 declared, 1 given)
   980    "\00\41\00\0b\01\00"                    ;; elem 0
   981    "\00\41\00"                             ;; elem 1 (partial)
   982    ;; "\0b\01\00"                          ;; elem 1 (missing part)
   983  )
   984  "unexpected end"
   985)
   986
   987;; 1 elem segment declared, 2 given
   988(assert_malformed
   989  (module binary
   990    "\00asm" "\01\00\00\00"
   991    "\01\04\01"                             ;; type section
   992    "\60\00\00"                             ;; type 0
   993    "\03\02\01\00"                          ;; func section
   994    "\04\04\01"                             ;; table section
   995    "\70\00\01"                             ;; table 0
   996    "\09\0d\01"                             ;; elem with inconsistent segment count (1 declared, 2 given)
   997    "\00\41\00\0b\01\00"                    ;; elem 0
   998    "\00\41\00\0b\01\00"                    ;; elem 1 (redundant)
   999    "\0a\04\01"                             ;; code section
  1000    "\02\00\0b"                             ;; function body
  1001  )
  1002  "section size mismatch"
  1003)
  1004
  1005;; data segment count can be zero
  1006(module binary
  1007  "\00asm" "\01\00\00\00"
  1008  "\05\03\01"                               ;; memory section
  1009  "\00\01"                                  ;; memory 0
  1010  "\0b\01\00"                               ;; data segment count can be zero
  1011)
  1012
  1013;; 2 data segment declared, 1 given
  1014(assert_malformed
  1015  (module binary
  1016    "\00asm" "\01\00\00\00"
  1017    "\05\03\01"                             ;; memory section
  1018    "\00\01"                                ;; memory 0
  1019    "\0b\07\02"                             ;; data with inconsistent segment count (2 declared, 1 given)
  1020    "\00\41\00\0b\01\61"                    ;; data 0
  1021    ;; "\00\41\01\0b\01\62"                 ;; data 1 (missed)
  1022  )
  1023  "unexpected end of section or function"
  1024)
  1025
  1026;; 1 data segment declared, 2 given
  1027(assert_malformed
  1028  (module binary
  1029    "\00asm" "\01\00\00\00"
  1030    "\05\03\01"                             ;; memory section
  1031    "\00\01"                                ;; memory 0
  1032    "\0b\0d\01"                             ;; data with inconsistent segment count (1 declared, 2 given)
  1033    "\00\41\00\0b\01\61"                    ;; data 0
  1034    "\00\41\01\0b\01\62"                    ;; data 1 (redundant)
  1035  )
  1036  "section size mismatch"
  1037)
  1038
  1039;; data segment has 7 bytes declared, but 6 bytes given
  1040(assert_malformed
  1041  (module binary
  1042    "\00asm" "\01\00\00\00"
  1043    "\05\03\01"                             ;; memory section
  1044    "\00\01"                                ;; memory 0
  1045    "\0b\0c\01"                             ;; data section
  1046    "\00\41\03\0b"                          ;; data segment 0
  1047    "\07"                                   ;; data segment size with inconsistent lengths (7 declared, 6 given)
  1048    "\61\62\63\64\65\66"                    ;; 6 bytes given
  1049  )
  1050  "unexpected end of section or function"
  1051)
  1052
  1053;; data segment has 5 bytes declared, but 6 bytes given
  1054(assert_malformed
  1055  (module binary
  1056    "\00asm" "\01\00\00\00"
  1057    "\05\03\01"                             ;; memory section
  1058    "\00\01"                                ;; memory 0
  1059    "\0b\0c\01"                             ;; data section
  1060    "\00\41\00\0b"                          ;; data segment 0
  1061    "\05"                                   ;; data segment size with inconsistent lengths (5 declared, 6 given)
  1062    "\61\62\63\64\65\66"                    ;; 6 bytes given
  1063  )
  1064  "section size mismatch"
  1065)
  1066
  1067;; br_table target count can be zero
  1068(module binary
  1069  "\00asm" "\01\00\00\00"
  1070  "\01\04\01"                               ;; type section
  1071  "\60\00\00"                               ;; type 0
  1072  "\03\02\01\00"                            ;; func section
  1073  "\0a\11\01"                               ;; code section
  1074  "\0f\00"                                  ;; func 0
  1075  "\02\40"                                  ;; block 0
  1076  "\41\01"                                  ;; condition of if 0
  1077  "\04\40"                                  ;; if 0
  1078  "\41\01"                                  ;; index of br_table element
  1079  "\0e\00"                                  ;; br_table target count can be zero
  1080  "\02"                                     ;; break depth for default
  1081  "\0b\0b\0b"                               ;; end
  1082)
  1083
  1084;; 1 br_table target declared, 2 given
  1085(assert_malformed
  1086  (module binary
  1087    "\00asm" "\01\00\00\00"
  1088    "\01\04\01"                             ;; type section
  1089    "\60\00\00"                             ;; type 0
  1090    "\03\02\01\00"                          ;; func section
  1091    "\0a\13\01"                             ;; code section
  1092    "\11\00"                                ;; func 0
  1093    "\02\40"                                ;; block 0
  1094    "\41\01"                                ;; condition of if 0
  1095    "\04\40"                                ;; if 0
  1096    "\41\01"                                ;; index of br_table element
  1097    "\0e\01"                                ;; br_table with inconsistent target count (1 declared, 2 given)
  1098    "\00"                                   ;; break depth 0
  1099    "\01"                                   ;; break depth 1
  1100    "\02"                                   ;; break depth for default
  1101    "\0b\0b\0b"                             ;; end
  1102  )
  1103  "unexpected end"
  1104)
  1105
  1106;; Start section
  1107(module binary
  1108  "\00asm" "\01\00\00\00"
  1109  "\01\04\01\60\00\00"       ;; Type section
  1110  "\03\02\01\00"             ;; Function section
  1111  "\08\01\00"                ;; Start section: function 0
  1112
  1113  "\0a\04\01"                ;; Code section
  1114  ;; function 0
  1115  "\02\00"
  1116  "\0b"                      ;; end
  1117)
  1118
  1119;; Multiple start sections
  1120(assert_malformed
  1121  (module binary
  1122    "\00asm" "\01\00\00\00"
  1123    "\01\04\01\60\00\00"       ;; Type section
  1124    "\03\02\01\00"             ;; Function section
  1125    "\08\01\00"                ;; Start section: function 0
  1126    "\08\01\00"                ;; Start section: function 0
  1127
  1128    "\0a\04\01"                ;; Code section
  1129    ;; function 0
  1130    "\02\00"
  1131    "\0b"                      ;; end
  1132  )
  1133  "unexpected content after last section"
  1134)

View as plain text