github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/binary.wast (about)

     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  
    48  ;; call_indirect reserved byte equal to zero.
    49  (assert_malformed
    50    (module binary
    51      "\00asm" "\01\00\00\00"
    52      "\01\04\01\60\00\00"      ;; Type section
    53      "\03\02\01\00"            ;; Function section
    54      "\04\04\01\70\00\00"      ;; Table section
    55      "\0a\09\01"               ;; Code section
    56  
    57      ;; function 0
    58      "\07\00"
    59      "\41\00"                   ;; i32.const 0
    60      "\11\00"                   ;; call_indirect (type 0)
    61      "\01"                      ;; call_indirect reserved byte is not equal to zero!
    62      "\0b"                      ;; end
    63    )
    64    "zero flag expected"
    65  )
    66  
    67  ;; call_indirect reserved byte should not be a "long" LEB128 zero.
    68  (assert_malformed
    69    (module binary
    70      "\00asm" "\01\00\00\00"
    71      "\01\04\01\60\00\00"      ;; Type section
    72      "\03\02\01\00"            ;; Function section
    73      "\04\04\01\70\00\00"      ;; Table section
    74      "\0a\0a\01"               ;; Code section
    75  
    76      ;; function 0
    77      "\07\00"
    78      "\41\00"                   ;; i32.const 0
    79      "\11\00"                   ;; call_indirect (type 0)
    80      "\80\00"                   ;; call_indirect reserved byte
    81      "\0b"                      ;; end
    82    )
    83    "zero flag expected"
    84  )
    85  
    86  ;; Same as above for 3, 4, and 5-byte zero encodings.
    87  (assert_malformed
    88    (module binary
    89      "\00asm" "\01\00\00\00"
    90      "\01\04\01\60\00\00"      ;; Type section
    91      "\03\02\01\00"            ;; Function section
    92      "\04\04\01\70\00\00"      ;; Table section
    93      "\0a\0b\01"               ;; Code section
    94  
    95      ;; function 0
    96      "\08\00"
    97      "\41\00"                   ;; i32.const 0
    98      "\11\00"                   ;; call_indirect (type 0)
    99      "\80\80\00"                ;; call_indirect reserved byte
   100      "\0b"                      ;; end
   101    )
   102    "zero flag expected"
   103  )
   104  
   105  (assert_malformed
   106    (module binary
   107      "\00asm" "\01\00\00\00"
   108      "\01\04\01\60\00\00"      ;; Type section
   109      "\03\02\01\00"            ;; Function section
   110      "\04\04\01\70\00\00"      ;; Table section
   111      "\0a\0c\01"               ;; Code section
   112  
   113      ;; function 0
   114      "\09\00"
   115      "\41\00"                   ;; i32.const 0
   116      "\11\00"                   ;; call_indirect (type 0)
   117      "\80\80\80\00"             ;; call_indirect reserved byte
   118      "\0b"                      ;; end
   119    )
   120    "zero flag expected"
   121  )
   122  
   123  (assert_malformed
   124    (module binary
   125      "\00asm" "\01\00\00\00"
   126      "\01\04\01\60\00\00"      ;; Type section
   127      "\03\02\01\00"            ;; Function section
   128      "\04\04\01\70\00\00"      ;; Table section
   129      "\0a\0d\01"               ;; Code section
   130  
   131      ;; function 0
   132      "\0a\00"
   133      "\41\00"                   ;; i32.const 0
   134      "\11\00"                   ;; call_indirect (type 0)
   135      "\80\80\80\80\00"          ;; call_indirect reserved byte
   136      "\0b"                      ;; end
   137    )
   138    "zero flag expected"
   139  )
   140  
   141  ;; memory.grow reserved byte equal to zero.
   142  (assert_malformed
   143    (module binary
   144      "\00asm" "\01\00\00\00"
   145      "\01\04\01\60\00\00"       ;; Type section
   146      "\03\02\01\00"             ;; Function section
   147      "\05\03\01\00\00"          ;; Memory section
   148      "\0a\09\01"                ;; Code section
   149  
   150      ;; function 0
   151      "\07\00"
   152      "\41\00"                   ;; i32.const 0
   153      "\40"                      ;; memory.grow
   154      "\01"                      ;; memory.grow reserved byte is not equal to zero!
   155      "\1a"                      ;; drop
   156      "\0b"                      ;; end
   157    )
   158    "zero flag expected"
   159  )
   160  
   161  ;; memory.grow reserved byte should not be a "long" LEB128 zero.
   162  (assert_malformed
   163    (module binary
   164      "\00asm" "\01\00\00\00"
   165      "\01\04\01\60\00\00"       ;; Type section
   166      "\03\02\01\00"             ;; Function section
   167      "\05\03\01\00\00"          ;; Memory section
   168      "\0a\0a\01"                ;; Code section
   169  
   170      ;; function 0
   171      "\08\00"
   172      "\41\00"                   ;; i32.const 0
   173      "\40"                      ;; memory.grow
   174      "\80\00"                   ;; memory.grow reserved byte
   175      "\1a"                      ;; drop
   176      "\0b"                      ;; end
   177    )
   178    "zero flag expected"
   179  )
   180  
   181  ;; Same as above for 3, 4, and 5-byte zero encodings.
   182  (assert_malformed
   183    (module binary
   184      "\00asm" "\01\00\00\00"
   185      "\01\04\01\60\00\00"       ;; Type section
   186      "\03\02\01\00"             ;; Function section
   187      "\05\03\01\00\00"          ;; Memory section
   188      "\0a\0b\01"                ;; Code section
   189  
   190      ;; function 0
   191      "\09\00"
   192      "\41\00"                   ;; i32.const 0
   193      "\40"                      ;; memory.grow
   194      "\80\80\00"                ;; memory.grow reserved byte
   195      "\1a"                      ;; drop
   196      "\0b"                      ;; end
   197    )
   198    "zero flag expected"
   199  )
   200  
   201  (assert_malformed
   202    (module binary
   203      "\00asm" "\01\00\00\00"
   204      "\01\04\01\60\00\00"       ;; Type section
   205      "\03\02\01\00"             ;; Function section
   206      "\05\03\01\00\00"          ;; Memory section
   207      "\0a\0c\01"                ;; Code section
   208  
   209      ;; function 0
   210      "\0a\00"
   211      "\41\00"                   ;; i32.const 0
   212      "\40"                      ;; memory.grow
   213      "\80\80\80\00"             ;; memory.grow reserved byte
   214      "\1a"                      ;; drop
   215      "\0b"                      ;; end
   216    )
   217    "zero flag expected"
   218  )
   219  
   220  (assert_malformed
   221    (module binary
   222      "\00asm" "\01\00\00\00"
   223      "\01\04\01\60\00\00"       ;; Type section
   224      "\03\02\01\00"             ;; Function section
   225      "\05\03\01\00\00"          ;; Memory section
   226      "\0a\0d\01"                ;; Code section
   227  
   228      ;; function 0
   229      "\0b\00"
   230      "\41\00"                   ;; i32.const 0
   231      "\40"                      ;; memory.grow
   232      "\80\80\80\80\00"          ;; memory.grow reserved byte
   233      "\1a"                      ;; drop
   234      "\0b"                      ;; end
   235    )
   236    "zero flag expected"
   237  )
   238  
   239  ;; memory.size reserved byte equal to zero.
   240  (assert_malformed
   241    (module binary
   242      "\00asm" "\01\00\00\00"
   243      "\01\04\01\60\00\00"       ;; Type section
   244      "\03\02\01\00"             ;; Function section
   245      "\05\03\01\00\00"          ;; Memory section
   246      "\0a\07\01"                ;; Code section
   247  
   248      ;; function 0
   249      "\05\00"
   250      "\3f"                      ;; memory.size
   251      "\01"                      ;; memory.size reserved byte is not equal to zero!
   252      "\1a"                      ;; drop
   253      "\0b"                      ;; end
   254    )
   255    "zero flag expected"
   256  )
   257  
   258  ;; memory.size reserved byte should not be a "long" LEB128 zero.
   259  (assert_malformed
   260    (module binary
   261      "\00asm" "\01\00\00\00"
   262      "\01\04\01\60\00\00"       ;; Type section
   263      "\03\02\01\00"             ;; Function section
   264      "\05\03\01\00\00"          ;; Memory section
   265      "\0a\08\01"                ;; Code section
   266  
   267      ;; function 0
   268      "\06\00"
   269      "\3f"                      ;; memory.size
   270      "\80\00"                   ;; memory.size reserved byte
   271      "\1a"                      ;; drop
   272      "\0b"                      ;; end
   273    )
   274    "zero flag expected"
   275  )
   276  
   277  ;; Same as above for 3, 4, and 5-byte zero encodings.
   278  (assert_malformed
   279    (module binary
   280      "\00asm" "\01\00\00\00"
   281      "\01\04\01\60\00\00"       ;; Type section
   282      "\03\02\01\00"             ;; Function section
   283      "\05\03\01\00\00"          ;; Memory section
   284      "\0a\09\01"                ;; Code section
   285  
   286      ;; function 0
   287      "\07\00"
   288      "\3f"                      ;; memory.size
   289      "\80\80\00"                ;; memory.size reserved byte
   290      "\1a"                      ;; drop
   291      "\0b"                      ;; end
   292    )
   293    "zero flag expected"
   294  )
   295  
   296  (assert_malformed
   297    (module binary
   298      "\00asm" "\01\00\00\00"
   299      "\01\04\01\60\00\00"       ;; Type section
   300      "\03\02\01\00"             ;; Function section
   301      "\05\03\01\00\00"          ;; Memory section
   302      "\0a\0a\01"                ;; Code section
   303  
   304      ;; function 0
   305      "\08\00"
   306      "\3f"                      ;; memory.size
   307      "\80\80\80\00"             ;; memory.size reserved byte
   308      "\1a"                      ;; drop
   309      "\0b"                      ;; end
   310    )
   311    "zero flag expected"
   312  )
   313  
   314  (assert_malformed
   315    (module binary
   316      "\00asm" "\01\00\00\00"
   317      "\01\04\01\60\00\00"       ;; Type section
   318      "\03\02\01\00"             ;; Function section
   319      "\05\03\01\00\00"          ;; Memory section
   320      "\0a\0b\01"                ;; Code section
   321  
   322      ;; function 0
   323      "\09\00"
   324      "\3f"                      ;; memory.size
   325      "\80\80\80\80\00"          ;; memory.size reserved byte
   326      "\1a"                      ;; drop
   327      "\0b"                      ;; end
   328    )
   329    "zero flag expected"
   330  )
   331  
   332  ;; No more than 2^32 locals.
   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      "\ff\ff\ff\ff\0f\7f"       ;; 0xFFFFFFFF i32
   343      "\02\7e"                   ;; 0x00000002 i64
   344      "\0b"                      ;; end
   345    )
   346    "too many locals"
   347  )
   348  
   349  ;; Local count can be 0.
   350  (module binary
   351    "\00asm" "\01\00\00\00"
   352    "\01\04\01\60\00\00"     ;; Type section
   353    "\03\02\01\00"           ;; Function section
   354    "\0a\0a\01"              ;; Code section
   355  
   356    ;; function 0
   357    "\08\03"
   358    "\00\7f"                 ;; 0 i32
   359    "\00\7e"                 ;; 0 i64
   360    "\02\7d"                 ;; 2 f32
   361    "\0b"                    ;; end
   362  )
   363  
   364  ;; Function section has non-zero count, but code section is absent.
   365  (assert_malformed
   366    (module binary
   367      "\00asm" "\01\00\00\00"
   368      "\01\04\01\60\00\00"  ;; Type section
   369      "\03\03\02\00\00"     ;; Function section with 2 functions
   370    )
   371    "function and code section have inconsistent lengths"
   372  )
   373  
   374  ;; Code section has non-zero count, but function section is absent.
   375  (assert_malformed
   376    (module binary
   377      "\00asm" "\01\00\00\00"
   378      "\0a\04\01\02\00\0b"  ;; Code section with 1 empty function
   379    )
   380    "function and code section have inconsistent lengths"
   381  )
   382  
   383  ;; Function section count > code section count
   384  (assert_malformed
   385    (module binary
   386      "\00asm" "\01\00\00\00"
   387      "\01\04\01\60\00\00"  ;; Type section
   388      "\03\03\02\00\00"     ;; Function section with 2 functions
   389      "\0a\04\01\02\00\0b"  ;; Code section with 1 empty function
   390    )
   391    "function and code section have inconsistent lengths"
   392  )
   393  
   394  ;; Function section count < code section count
   395  (assert_malformed
   396    (module binary
   397      "\00asm" "\01\00\00\00"
   398      "\01\04\01\60\00\00"           ;; Type section
   399      "\03\02\01\00"                 ;; Function section with 1 function
   400      "\0a\07\02\02\00\0b\02\00\0b"  ;; Code section with 2 empty functions
   401    )
   402    "function and code section have inconsistent lengths"
   403  )
   404  
   405  ;; Function section has zero count, and code section is absent.
   406  (module binary
   407    "\00asm" "\01\00\00\00"
   408    "\03\01\00"  ;; Function section with 0 functions
   409  )
   410  
   411  ;; Code section has zero count, and function section is absent.
   412  (module binary
   413    "\00asm" "\01\00\00\00"
   414    "\0a\01\00"  ;; Code section with 0 functions
   415  )
   416  
   417  ;; Type count can be zero
   418  (module binary
   419    "\00asm" "\01\00\00\00"
   420    "\01\01\00"                               ;; type count can be zero
   421  )
   422  
   423  ;; 2 type declared, 1 given
   424  (assert_malformed
   425    (module binary
   426      "\00asm" "\01\00\00\00"
   427      "\01\07\02"                             ;; type section with inconsistent count (2 declared, 1 given)
   428      "\60\00\00"                             ;; 1st type
   429      ;; "\60\00\00"                          ;; 2nd type (missed)
   430    )
   431    "unexpected end of section or function"
   432  )
   433  
   434  ;; 1 type declared, 2 given
   435  (assert_malformed
   436    (module binary
   437      "\00asm" "\01\00\00\00"
   438      "\01\07\01"                             ;; type section with inconsistent count (1 declared, 2 given)
   439      "\60\00\00"                             ;; 1st type
   440      "\60\00\00"                             ;; 2nd type (redundant)
   441    )
   442    "section size mismatch"
   443  )
   444  
   445  ;; Import count can be zero
   446  (module binary
   447      "\00asm" "\01\00\00\00"
   448      "\01\05\01"                             ;; type section
   449      "\60\01\7f\00"                          ;; type 0
   450      "\02\01\00"                             ;; import count can be zero
   451  )
   452  
   453  ;; 2 import declared, 1 given
   454  (assert_malformed
   455    (module binary
   456        "\00asm" "\01\00\00\00"
   457        "\01\05\01"                           ;; type section
   458        "\60\01\7f\00"                        ;; type 0
   459        "\02\16\02"                           ;; import section with inconsistent count (2 declared, 1 given)
   460        ;; 1st import
   461        "\08"                                 ;; string length
   462        "\73\70\65\63\74\65\73\74"            ;; spectest
   463        "\09"                                 ;; string length
   464        "\70\72\69\6e\74\5f\69\33\32"         ;; print_i32
   465        "\00\00"                              ;; import kind, import signature index
   466        ;; 2nd import
   467        ;; (missed)
   468    )
   469    "unexpected end of section or function"
   470  )
   471  
   472  ;; 1 import declared, 2 given
   473  (assert_malformed
   474    (module binary
   475        "\00asm" "\01\00\00\00"
   476        "\01\09\02"                           ;; type section
   477        "\60\01\7f\00"                        ;; type 0
   478        "\60\01\7d\00"                        ;; type 1
   479        "\02\2b\01"                           ;; import section with inconsistent count (1 declared, 2 given)
   480        ;; 1st import
   481        "\08"                                 ;; string length
   482        "\73\70\65\63\74\65\73\74"            ;; spectest
   483        "\09"                                 ;; string length
   484        "\70\72\69\6e\74\5f\69\33\32"         ;; print_i32
   485        "\00\00"                              ;; import kind, import signature index
   486        ;; 2nd import
   487        ;; (redundant)
   488        "\08"                                 ;; string length
   489        "\73\70\65\63\74\65\73\74"            ;; spectest
   490        "\09"                                 ;; string length
   491        "\70\72\69\6e\74\5f\66\33\32"         ;; print_f32
   492        "\00\01"                              ;; import kind, import signature index
   493    )
   494    "section size mismatch"
   495  )
   496  
   497  ;; Table count can be zero
   498  (module binary
   499      "\00asm" "\01\00\00\00"
   500      "\04\01\00"                             ;; table count can be zero
   501  )
   502  
   503  ;; 1 table declared, 0 given
   504  (assert_malformed
   505    (module binary
   506        "\00asm" "\01\00\00\00"
   507        "\04\01\01"                           ;; table section with inconsistent count (1 declared, 0 given)
   508        ;; "\70\01\00\00"                     ;; table entity
   509    )
   510    "unexpected end of section or function"
   511  )
   512  
   513  ;; Memory count can be zero
   514  (module binary
   515      "\00asm" "\01\00\00\00"
   516      "\05\01\00"                             ;; memory count can be zero
   517  )
   518  
   519  ;; 1 memory declared, 0 given
   520  (assert_malformed
   521    (module binary
   522        "\00asm" "\01\00\00\00"
   523        "\05\01\01"                           ;; memory section with inconsistent count (1 declared, 0 given)
   524        ;; "\00\00"                           ;; memory 0 (missed)
   525    )
   526    "unexpected end of section or function"
   527  )
   528  
   529  ;; Global count can be zero
   530  (module binary
   531    "\00asm" "\01\00\00\00"
   532    "\06\01\00"                               ;; global count can be zero
   533  )
   534  
   535  ;; 2 global declared, 1 given
   536  (assert_malformed
   537    (module binary
   538      "\00asm" "\01\00\00\00"
   539      "\06\06\02"                             ;; global section with inconsistent count (2 declared, 1 given)
   540      "\7f\00\41\00\0b"                       ;; global 0
   541      ;; "\7f\00\41\00\0b"                    ;; global 1 (missed)
   542    )
   543    "unexpected end of section or function"
   544  )
   545  
   546  ;; 1 global declared, 2 given
   547  (assert_malformed
   548    (module binary
   549      "\00asm" "\01\00\00\00"
   550      "\06\0b\01"                             ;; global section with inconsistent count (1 declared, 2 given)
   551      "\7f\00\41\00\0b"                       ;; global 0
   552      "\7f\00\41\00\0b"                       ;; global 1 (redundant)
   553    )
   554    "section size mismatch"
   555  )
   556  
   557  ;; Export count can be 0
   558  (module binary
   559    "\00asm" "\01\00\00\00"
   560    "\01\04\01"                               ;; type section
   561    "\60\00\00"                               ;; type 0
   562    "\03\03\02\00\00"                         ;; func section
   563    "\07\01\00"                               ;; export count can be zero
   564    "\0a\07\02"                               ;; code section
   565    "\02\00\0b"                               ;; function body 0
   566    "\02\00\0b"                               ;; function body 1
   567  )
   568  
   569  ;; 2 export declared, 1 given
   570  (assert_malformed
   571    (module binary
   572      "\00asm" "\01\00\00\00"
   573      "\01\04\01"                             ;; type section
   574      "\60\00\00"                             ;; type 0
   575      "\03\03\02\00\00"                       ;; func section
   576      "\07\06\02"                             ;; export section with inconsistent count (2 declared, 1 given)
   577      "\02"                                   ;; export 0
   578      "\66\31"                                ;; export name
   579      "\00\00"                                ;; export kind, export func index
   580      ;; "\02"                                ;; export 1 (missed)
   581      ;; "\66\32"                             ;; export name
   582      ;; "\00\01"                             ;; export kind, export func index
   583      "\0a\07\02"                             ;; code section
   584      "\02\00\0b"                             ;; function body 0
   585      "\02\00\0b"                             ;; function body 1
   586    )
   587    "unexpected end of section or function"
   588  )
   589  
   590  ;; 1 export declared, 2 given
   591  (assert_malformed
   592    (module binary
   593      "\00asm" "\01\00\00\00"
   594      "\01\04\01"                             ;; type section
   595      "\60\00\00"                             ;; type 0
   596      "\03\03\02\00\00"                       ;; func section
   597      "\07\0b\01"                             ;; export section with inconsistent count (1 declared, 2 given)
   598      "\02"                                   ;; export 0
   599      "\66\31"                                ;; export name
   600      "\00\00"                                ;; export kind, export func index
   601      "\02"                                   ;; export 1 (redundant)
   602      "\66\32"                                ;; export name
   603      "\00\01"                                ;; export kind, export func index
   604      "\0a\07\02"                             ;; code section
   605      "\02\00\0b"                             ;; function body 0
   606      "\02\00\0b"                             ;; function body 1
   607    )
   608    "section size mismatch"
   609  )
   610  
   611  ;; elem segment count can be zero
   612  (module binary
   613    "\00asm" "\01\00\00\00"
   614    "\01\04\01"                               ;; type section
   615    "\60\00\00"                               ;; type 0
   616    "\03\02\01\00"                            ;; func section
   617    "\04\04\01"                               ;; table section
   618    "\70\00\01"                               ;; table 0
   619    "\09\01\00"                               ;; elem segment count can be zero
   620    "\0a\04\01"                               ;; code section
   621    "\02\00\0b"                               ;; function body
   622  )
   623  
   624  ;; 2 elem segment declared, 1 given
   625  (assert_malformed
   626    (module binary
   627      "\00asm" "\01\00\00\00"
   628      "\01\04\01"                             ;; type section
   629      "\60\00\00"                             ;; type 0
   630      "\03\02\01\00"                          ;; func section
   631      "\04\04\01"                             ;; table section
   632      "\70\00\01"                             ;; table 0
   633      "\09\07\02"                             ;; elem with inconsistent segment count (2 declared, 1 given)
   634      "\00\41\00\0b\01\00"                    ;; elem 0
   635      ;; "\00\41\00\0b\01\00"                 ;; elem 1 (missed)
   636      "\0a\04\01"                             ;; code section
   637      "\02\00\0b"                             ;; function body
   638    )
   639    "invalid value type"
   640  )
   641  
   642  ;; 1 elem segment declared, 2 given
   643  (assert_malformed
   644    (module binary
   645      "\00asm" "\01\00\00\00"
   646      "\01\04\01"                             ;; type section
   647      "\60\00\00"                             ;; type 0
   648      "\03\02\01\00"                          ;; func section
   649      "\04\04\01"                             ;; table section
   650      "\70\00\01"                             ;; table 0
   651      "\09\0d\01"                             ;; elem with inconsistent segment count (1 declared, 2 given)
   652      "\00\41\00\0b\01\00"                    ;; elem 0
   653      "\00\41\00\0b\01\00"                    ;; elem 1 (redundant)
   654      "\0a\04\01"                             ;; code section
   655      "\02\00\0b"                             ;; function body
   656    )
   657    "section size mismatch"
   658  )
   659  
   660  ;; data segment count can be zero
   661  (module binary
   662    "\00asm" "\01\00\00\00"
   663    "\05\03\01"                               ;; memory section
   664    "\00\01"                                  ;; memory 0
   665    "\0b\01\00"                               ;; data segment count can be zero
   666  )
   667  
   668  ;; 2 data segment declared, 1 given
   669  (assert_malformed
   670    (module binary
   671      "\00asm" "\01\00\00\00"
   672      "\05\03\01"                             ;; memory section
   673      "\00\01"                                ;; memory 0
   674      "\0b\07\02"                             ;; data with inconsistent segment count (2 declared, 1 given)
   675      "\00\41\00\0b\01\61"                    ;; data 0
   676      ;; "\00\41\01\0b\01\62"                 ;; data 1 (missed)
   677    )
   678    "unexpected end of section or function"
   679  )
   680  
   681  ;; 1 data segment declared, 2 given
   682  (assert_malformed
   683    (module binary
   684      "\00asm" "\01\00\00\00"
   685      "\05\03\01"                             ;; memory section
   686      "\00\01"                                ;; memory 0
   687      "\0b\0d\01"                             ;; data with inconsistent segment count (1 declared, 2 given)
   688      "\00\41\00\0b\01\61"                    ;; data 0
   689      "\00\41\01\0b\01\62"                    ;; data 1 (redundant)
   690    )
   691    "section size mismatch"
   692  )
   693  
   694  ;; data segment has 7 bytes declared, but 6 bytes given
   695  (assert_malformed
   696    (module binary
   697      "\00asm" "\01\00\00\00"
   698      "\05\03\01"                             ;; memory section
   699      "\00\01"                                ;; memory 0
   700      "\0b\0c\01"                             ;; data section
   701      "\00\41\03\0b"                          ;; data segment 0
   702      "\07"                                   ;; data segment size with inconsistent lengths (7 declared, 6 given)
   703      "\61\62\63\64\65\66"                    ;; 6 bytes given
   704    )
   705    "unexpected end of section or function"
   706  )
   707  
   708  ;; data segment has 5 bytes declared, but 6 bytes given
   709  (assert_malformed
   710    (module binary
   711      "\00asm" "\01\00\00\00"
   712      "\05\03\01"                             ;; memory section
   713      "\00\01"                                ;; memory 0
   714      "\0b\0c\01"                             ;; data section
   715      "\00\41\00\0b"                          ;; data segment 0
   716      "\05"                                   ;; data segment size with inconsistent lengths (5 declared, 6 given)
   717      "\61\62\63\64\65\66"                    ;; 6 bytes given
   718    )
   719    "section size mismatch"
   720  )
   721  
   722  ;; br_table target count can be zero
   723  (module binary
   724    "\00asm" "\01\00\00\00"
   725    "\01\04\01"                               ;; type section
   726    "\60\00\00"                               ;; type 0
   727    "\03\02\01\00"                            ;; func section
   728    "\0a\11\01"                               ;; code section
   729    "\0f\00"                                  ;; func 0
   730    "\02\40"                                  ;; block 0
   731    "\41\01"                                  ;; condition of if 0
   732    "\04\40"                                  ;; if 0
   733    "\41\01"                                  ;; index of br_table element
   734    "\0e\00"                                  ;; br_table target count can be zero
   735    "\02"                                     ;; break depth for default
   736    "\0b\0b\0b"                               ;; end
   737  )
   738  
   739  ;; 2 br_table target declared, 1 given
   740  (assert_malformed
   741    (module binary
   742      "\00asm" "\01\00\00\00"
   743      "\01\04\01"                             ;; type section
   744      "\60\00\00"                             ;; type 0
   745      "\03\02\01\00"                          ;; func section
   746      "\0a\12\01"                             ;; code section
   747      "\10\00"                                ;; func 0
   748      "\02\40"                                ;; block 0
   749      "\41\01"                                ;; condition of if 0
   750      "\04\40"                                ;; if 0
   751      "\41\01"                                ;; index of br_table element
   752      "\0e\02"                                ;; br_table with inconsistent target count (2 declared, 1 given)
   753      "\00"                                   ;; break depth 0
   754      ;; "\01"                                ;; break depth 1 (missed)
   755      "\02"                                   ;; break depth for default
   756      "\0b\0b\0b"                             ;; end
   757    )
   758    "unexpected end of section or function"
   759  )
   760  
   761  ;; 1 br_table target declared, 2 given
   762  (assert_malformed
   763    (module binary
   764      "\00asm" "\01\00\00\00"
   765      "\01\04\01"                             ;; type section
   766      "\60\00\00"                             ;; type 0
   767      "\03\02\01\00"                          ;; func section
   768      "\0a\12\01"                             ;; code section
   769      "\11\00"                                ;; func 0
   770      "\02\40"                                ;; block 0
   771      "\41\01"                                ;; condition of if 0
   772      "\04\40"                                ;; if 0
   773      "\41\01"                                ;; index of br_table element
   774      "\0e\01"                                ;; br_table with inconsistent target count (1 declared, 2 given)
   775      "\00"                                   ;; break depth 0
   776      "\01"                                   ;; break depth 1
   777      "\02"                                   ;; break depth for default
   778      "\0b\0b\0b"                             ;; end
   779    )
   780    "invalid value type"
   781  )