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

     1  ;; Unsigned LEB128 can have non-minimal length
     2  (module binary
     3    "\00asm" "\01\00\00\00"
     4    "\05\04\01"                          ;; Memory section with 1 entry
     5    "\00\82\00"                          ;; no max, minimum 2
     6  )
     7  (module binary
     8    "\00asm" "\01\00\00\00"
     9    "\05\07\01"                          ;; Memory section with 1 entry
    10    "\00\82\80\80\80\00"                 ;; no max, minimum 2
    11  )
    12  (module binary
    13    "\00asm" "\01\00\00\00"
    14    "\05\06\01"                          ;; Memory section with 1 entry
    15    "\01\82\00"                          ;; minimum 2
    16    "\82\00"                             ;; max 2
    17  )
    18  (module binary
    19    "\00asm" "\01\00\00\00"
    20    "\05\09\01"                          ;; Memory section with 1 entry
    21    "\01\82\00"                          ;; minimum 2
    22    "\82\80\80\80\00"                    ;; max 2
    23  )
    24  (module binary
    25    "\00asm" "\01\00\00\00"
    26    "\05\03\01"                          ;; Memory section with 1 entry
    27    "\00\00"                             ;; no max, minimum 0
    28    "\0b\07\01"                          ;; Data section with 1 entry
    29    "\80\00"                             ;; Memory index 0, encoded with 2 bytes
    30    "\41\00\0b\00"                       ;; (i32.const 0) with contents ""
    31  )
    32  (module binary
    33    "\00asm" "\01\00\00\00"
    34    "\04\04\01"                          ;; Table section with 1 entry
    35    "\70\00\00"                          ;; no max, minimum 0, funcref
    36    "\09\09\01"                          ;; Element section with 1 entry
    37    "\02"                                ;; Element with explicit table index
    38    "\80\00"                             ;; Table index 0, encoded with 2 bytes
    39    "\41\00\0b\00\00"                    ;; (i32.const 0) with no elements
    40  )
    41  (module binary
    42    "\00asm" "\01\00\00\00"
    43    "\00"                                ;; custom section
    44    "\8a\00"                             ;; section size 10, encoded with 2 bytes
    45    "\01"                                ;; name byte count
    46    "1"                                  ;; name
    47    "23456789"                           ;; sequence of bytes
    48  )
    49  (module binary
    50    "\00asm" "\01\00\00\00"
    51    "\00"                                ;; custom section
    52    "\0b"                                ;; section size
    53    "\88\00"                             ;; name byte count 8, encoded with 2 bytes
    54    "12345678"                           ;; name
    55    "9"                                  ;; sequence of bytes
    56  )
    57  (module binary
    58    "\00asm" "\01\00\00\00"
    59    "\01\08\01"                          ;; type section
    60    "\60"                                ;; func type
    61    "\82\00"                             ;; num params 2, encoded with 2 bytes
    62    "\7f\7e"                             ;; param type
    63    "\01"                                ;; num results
    64    "\7f"                                ;; result type
    65  )
    66  (module binary
    67    "\00asm" "\01\00\00\00"
    68    "\01\08\01"                          ;; type section
    69    "\60"                                ;; func type
    70    "\02"                                ;; num params
    71    "\7f\7e"                             ;; param type
    72    "\81\00"                             ;; num results 1, encoded with 2 bytes
    73    "\7f"                                ;; result type
    74  )
    75  (module binary
    76    "\00asm" "\01\00\00\00"
    77    "\01\05\01"                          ;; type section
    78    "\60\01\7f\00"                       ;; function type
    79    "\02\17\01"                          ;; import section
    80    "\88\00"                             ;; module name length 8, encoded with 2 bytes
    81    "\73\70\65\63\74\65\73\74"           ;; module name
    82    "\09"                                ;; entity name length
    83    "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
    84    "\00"                                ;; import kind
    85    "\00"                                ;; import signature index
    86  )
    87  (module binary
    88    "\00asm" "\01\00\00\00"
    89    "\01\05\01"                          ;; type section
    90    "\60\01\7f\00"                       ;; function type
    91    "\02\17\01"                          ;; import section
    92    "\08"                                ;; module name length
    93    "\73\70\65\63\74\65\73\74"           ;; module name
    94    "\89\00"                             ;; entity name length 9, encoded with 2 bytes
    95    "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
    96    "\00"                                ;; import kind
    97    "\00"                                ;; import signature index
    98  )
    99  (module binary
   100    "\00asm" "\01\00\00\00"
   101    "\01\05\01"                          ;; type section
   102    "\60\01\7f\00"                       ;; function type
   103    "\02\17\01"                          ;; import section
   104    "\08"                                ;; module name length
   105    "\73\70\65\63\74\65\73\74"           ;; module name
   106    "\09"                                ;; entity name length 9
   107    "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   108    "\00"                                ;; import kind
   109    "\80\00"                             ;; import signature index, encoded with 2 bytes
   110  )
   111  (module binary
   112    "\00asm" "\01\00\00\00"
   113    "\01\04\01"                          ;; type section
   114    "\60\00\00"                          ;; function type
   115    "\03\03\01"                          ;; function section
   116    "\80\00"                             ;; function 0 signature index, encoded with 2 bytes
   117    "\0a\04\01"                          ;; code section
   118    "\02\00\0b"                          ;; function body
   119  )
   120  (module binary
   121    "\00asm" "\01\00\00\00"
   122    "\01\04\01"                          ;; type section
   123    "\60\00\00"                          ;; fun type
   124    "\03\02\01\00"                       ;; function section
   125    "\07\07\01"                          ;; export section
   126    "\82\00"                             ;; string length 2, encoded with 2 bytes
   127    "\66\31"                             ;; export name f1
   128    "\00"                                ;; export kind
   129    "\00"                                ;; export func index
   130    "\0a\04\01"                          ;; code section
   131    "\02\00\0b"                          ;; function body
   132  )
   133  (module binary
   134    "\00asm" "\01\00\00\00"
   135    "\01\04\01"                          ;; type section
   136    "\60\00\00"                          ;; fun type
   137    "\03\02\01\00"                       ;; function section
   138    "\07\07\01"                          ;; export section
   139    "\02"                                ;; string length 2
   140    "\66\31"                             ;; export name f1
   141    "\00"                                ;; export kind
   142    "\80\00"                             ;; export func index, encoded with 2 bytes
   143    "\0a\04\01"                          ;; code section
   144    "\02\00\0b"                          ;; function body
   145  )
   146  (module binary
   147    "\00asm" "\01\00\00\00"
   148    "\01\04\01"                          ;; type section
   149    "\60\00\00"                          ;; fun type
   150    "\03\02\01\00"                       ;; function section
   151    "\0a"                                ;; code section
   152    "\05"                                ;; section size
   153    "\81\00"                             ;; num functions, encoded with 2 bytes
   154    "\02\00\0b"                          ;; function body
   155  )
   156  
   157  ;; Signed LEB128 can have non-minimal length
   158  (module binary
   159    "\00asm" "\01\00\00\00"
   160    "\06\07\01"                          ;; Global section with 1 entry
   161    "\7f\00"                             ;; i32, immutable
   162    "\41\80\00"                          ;; i32.const 0
   163    "\0b"                                ;; end
   164  )
   165  (module binary
   166    "\00asm" "\01\00\00\00"
   167    "\06\07\01"                          ;; Global section with 1 entry
   168    "\7f\00"                             ;; i32, immutable
   169    "\41\ff\7f"                          ;; i32.const -1
   170    "\0b"                                ;; end
   171  )
   172  (module binary
   173    "\00asm" "\01\00\00\00"
   174    "\06\0a\01"                          ;; Global section with 1 entry
   175    "\7f\00"                             ;; i32, immutable
   176    "\41\80\80\80\80\00"                 ;; i32.const 0
   177    "\0b"                                ;; end
   178  )
   179  (module binary
   180    "\00asm" "\01\00\00\00"
   181    "\06\0a\01"                          ;; Global section with 1 entry
   182    "\7f\00"                             ;; i32, immutable
   183    "\41\ff\ff\ff\ff\7f"                 ;; i32.const -1
   184    "\0b"                                ;; end
   185  )
   186  
   187  (module binary
   188    "\00asm" "\01\00\00\00"
   189    "\06\07\01"                          ;; Global section with 1 entry
   190    "\7e\00"                             ;; i64, immutable
   191    "\42\80\00"                          ;; i64.const 0 with unused bits set
   192    "\0b"                                ;; end
   193  )
   194  (module binary
   195    "\00asm" "\01\00\00\00"
   196    "\06\07\01"                          ;; Global section with 1 entry
   197    "\7e\00"                             ;; i64, immutable
   198    "\42\ff\7f"                          ;; i64.const -1 with unused bits unset
   199    "\0b"                                ;; end
   200  )
   201  (module binary
   202    "\00asm" "\01\00\00\00"
   203    "\06\0f\01"                          ;; Global section with 1 entry
   204    "\7e\00"                             ;; i64, immutable
   205    "\42\80\80\80\80\80\80\80\80\80\00"  ;; i64.const 0 with unused bits set
   206    "\0b"                                ;; end
   207  )
   208  (module binary
   209    "\00asm" "\01\00\00\00"
   210    "\06\0f\01"                          ;; Global section with 1 entry
   211    "\7e\00"                             ;; i64, immutable
   212    "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\7f"  ;; i64.const -1 with unused bits unset
   213    "\0b"                                ;; end
   214  )
   215  
   216  ;; Unsigned LEB128 must not be overlong
   217  (assert_malformed
   218    (module binary
   219      "\00asm" "\01\00\00\00"
   220      "\05\08\01"                          ;; Memory section with 1 entry
   221      "\00\82\80\80\80\80\00"              ;; no max, minimum 2 with one byte too many
   222    )
   223    "integer representation too long"
   224  )
   225  (assert_malformed
   226    (module binary
   227      "\00asm" "\01\00\00\00"
   228      "\05\0a\01"                          ;; Memory section with 1 entry
   229      "\01\82\00"                          ;; minimum 2
   230      "\82\80\80\80\80\00"                 ;; max 2 with one byte too many
   231    )
   232    "integer representation too long"
   233  )
   234  (assert_malformed
   235    (module binary
   236      "\00asm" "\01\00\00\00"
   237      "\05\03\01"                          ;; Memory section with 1 entry
   238      "\00\00"                             ;; no max, minimum 0
   239      "\0b\0b\01"                          ;; Data section with 1 entry
   240      "\80\80\80\80\80\00"                 ;; Memory index 0 with one byte too many
   241      "\41\00\0b\00"                       ;; (i32.const 0) with contents ""
   242    )
   243    "integer representation too long"
   244  )
   245  (assert_malformed
   246    (module binary
   247      "\00asm" "\01\00\00\00"
   248      "\04\04\01"                          ;; Table section with 1 entry
   249      "\70\00\00"                          ;; no max, minimum 0, funcref
   250      "\09\0b\01"                          ;; Element section with 1 entry
   251      "\80\80\80\80\80\00"                 ;; Table index 0 with one byte too many
   252      "\41\00\0b\00"                       ;; (i32.const 0) with no elements
   253    )
   254    "integer representation too long"
   255  )
   256  (assert_malformed
   257    (module binary
   258      "\00asm" "\01\00\00\00"
   259      "\00"                                ;; custom section
   260      "\83\80\80\80\80\00"                 ;; section size 3 with one byte too many
   261      "\01"                                ;; name byte count
   262      "1"                                  ;; name
   263      "2"                                  ;; sequence of bytes
   264    )
   265    "integer representation too long"
   266  )
   267  (assert_malformed
   268    (module binary
   269      "\00asm" "\01\00\00\00"
   270      "\00"                                ;; custom section
   271      "\0A"                                ;; section size
   272      "\83\80\80\80\80\00"                 ;; name byte count 3 with one byte too many
   273      "123"                                ;; name
   274      "4"                                  ;; sequence of bytes
   275    )
   276    "integer representation too long"
   277  )
   278  (assert_malformed
   279    (module binary
   280      "\00asm" "\01\00\00\00"
   281      "\01\0c\01"                          ;; type section
   282      "\60"                                ;; func type
   283      "\82\80\80\80\80\00"                 ;; num params 2 with one byte too many
   284      "\7f\7e"                             ;; param type
   285      "\01"                                ;; num result
   286      "\7f"                                ;; result type
   287    )
   288    "integer representation too long"
   289  )
   290  (assert_malformed
   291    (module binary
   292      "\00asm" "\01\00\00\00"
   293      "\01\0c\01"                          ;; type section
   294      "\60"                                ;; func type
   295      "\02"                                ;; num params
   296      "\7f\7e"                             ;; param type
   297      "\81\80\80\80\80\00"                 ;; num result 1 with one byte too many
   298      "\7f"                                ;; result type
   299    )
   300    "integer representation too long"
   301  )
   302  (assert_malformed
   303    (module binary
   304      "\00asm" "\01\00\00\00"
   305      "\01\05\01"                          ;; type section
   306      "\60\01\7f\00"                       ;; function type
   307      "\02\1b\01"                          ;; import section
   308      "\88\80\80\80\80\00"                 ;; module name length 8 with one byte too many
   309      "\73\70\65\63\74\65\73\74"           ;; module name
   310      "\09"                                ;; entity name length
   311      "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   312      "\00"                                ;; import kind
   313      "\00"                                ;; import signature index
   314    )
   315    "integer representation too long"
   316  )
   317  (assert_malformed
   318    (module binary
   319      "\00asm" "\01\00\00\00"
   320      "\01\05\01"                          ;; type section
   321      "\60\01\7f\00"                       ;; function type
   322      "\02\1b\01"                          ;; import section
   323      "\08"                                ;; module name length
   324      "\73\70\65\63\74\65\73\74"           ;; module name
   325      "\89\80\80\80\80\00"                 ;; entity name length 9 with one byte too many
   326      "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   327      "\00"                                ;; import kind
   328      "\00"                                ;; import signature index
   329    )
   330    "integer representation too long"
   331  )
   332  (assert_malformed
   333    (module binary
   334      "\00asm" "\01\00\00\00"
   335      "\01\05\01"                          ;; type section
   336      "\60\01\7f\00"                       ;; function type
   337      "\02\1b\01"                          ;; import section
   338      "\08"                                ;; module name length
   339      "\73\70\65\63\74\65\73\74"           ;; module name
   340      "\09"                                ;; entity name length 9
   341      "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   342      "\00"                                ;; import kind
   343      "\80\80\80\80\80\00"                 ;; import signature index 0 with one byte too many
   344    )
   345    "integer representation too long"
   346  )
   347  (assert_malformed
   348    (module binary
   349      "\00asm" "\01\00\00\00"
   350      "\01\04\01"                          ;; type section
   351      "\60\00\00"                          ;; function type
   352      "\03\03\01"                          ;; function section
   353      "\80\80\80\80\80\00"                 ;; function 0 signature index with one byte too many
   354      "\0a\04\01"                          ;; code section
   355      "\02\00\0b"                          ;; function body
   356    )
   357    "integer representation too long"
   358  )
   359  (assert_malformed
   360    (module binary
   361      "\00asm" "\01\00\00\00"
   362      "\01\04\01"                          ;; type section
   363      "\60\00\00"                          ;; fun type
   364      "\03\02\01\00"                       ;; function section
   365      "\07\0b\01"                          ;; export section
   366      "\82\80\80\80\80\00"                 ;; string length 2 with one byte too many
   367      "\66\31"                             ;; export name f1
   368      "\00"                                ;; export kind
   369      "\00"                                ;; export func index
   370      "\0a\04\01"                          ;; code section
   371      "\02\00\0b"                          ;; function body
   372    )
   373    "integer representation too long"
   374  )
   375  (assert_malformed
   376    (module binary
   377      "\00asm" "\01\00\00\00"
   378      "\01\04\01"                          ;; type section
   379      "\60\00\00"                          ;; fun type
   380      "\03\02\01\00"                       ;; function section
   381      "\07\0b\01"                          ;; export section
   382      "\02"                                ;; string length 2
   383      "\66\31"                             ;; export name f1
   384      "\00"                                ;; export kind
   385      "\80\80\80\80\80\00"                 ;; export func index 0 with one byte too many
   386      "\0a\04\01"                          ;; code section
   387      "\02\00\0b"                          ;; function body
   388    )
   389    "integer representation too long"
   390  )
   391  (assert_malformed
   392    (module binary
   393      "\00asm" "\01\00\00\00"
   394      "\01\04\01"                          ;; type section
   395      "\60\00\00"                          ;; fun type
   396      "\03\02\01\00"                       ;; function section
   397      "\0a"                                ;; code section
   398      "\05"                                ;; section size
   399      "\81\80\80\80\80\00"                 ;; num functions 1 with one byte too many
   400      "\02\00\0b"                          ;; function body
   401    )
   402    "integer representation too long"
   403  )
   404  (assert_malformed
   405    (module binary
   406      "\00asm" "\01\00\00\00"
   407      "\01\04\01\60\00\00"       ;; Type section
   408      "\03\02\01\00"             ;; Function section
   409      "\05\03\01\00\01"          ;; Memory section
   410      "\0a\11\01"                ;; Code section
   411      ;; function 0
   412      "\0f\01\01"                ;; local type count
   413      "\7f"                      ;; i32
   414      "\41\00"                   ;; i32.const 0
   415      "\28"                      ;; i32.load
   416      "\02"                      ;; alignment 2
   417      "\82\80\80\80\80\00"       ;; offset 2 with one byte too many
   418      "\1a"                      ;; drop
   419      "\0b"                      ;; end
   420    )
   421    "integer representation too long"
   422  )
   423  (assert_malformed
   424    (module binary
   425      "\00asm" "\01\00\00\00"
   426      "\01\04\01\60\00\00"       ;; Type section
   427      "\03\02\01\00"             ;; Function section
   428      "\05\03\01\00\01"          ;; Memory section
   429      "\0a\11\01"                ;; Code section
   430      ;; function 0
   431      "\0f\01\01"                ;; local type count
   432      "\7f"                      ;; i32
   433      "\41\00"                   ;; i32.const 0
   434      "\28"                      ;; i32.load
   435      "\82\80\80\80\80\00"       ;; alignment 2 with one byte too many
   436      "\00"                      ;; offset 0
   437      "\1a"                      ;; drop
   438      "\0b"                      ;; end
   439    )
   440    "integer representation too long"
   441  )
   442  (assert_malformed
   443    (module binary
   444      "\00asm" "\01\00\00\00"
   445      "\01\04\01\60\00\00"       ;; Type section
   446      "\03\02\01\00"             ;; Function section
   447      "\05\03\01\00\01"          ;; Memory section
   448      "\0a\12\01"                ;; Code section
   449      ;; function 0
   450      "\10\01\01"                ;; local type count
   451      "\7f"                      ;; i32
   452      "\41\00"                   ;; i32.const 0
   453      "\41\03"                   ;; i32.const 3
   454      "\36"                      ;; i32.store
   455      "\82\80\80\80\80\00"       ;; alignment 2 with one byte too many
   456      "\03"                      ;; offset 3
   457      "\0b"                      ;; end
   458    )
   459    "integer representation too long"
   460  )
   461  (assert_malformed
   462    (module binary
   463      "\00asm" "\01\00\00\00"
   464      "\01\04\01\60\00\00"       ;; Type section
   465      "\03\02\01\00"             ;; Function section
   466      "\05\03\01\00\01"          ;; Memory section
   467      "\0a\12\01"                ;; Code section
   468      ;; function 0
   469      "\10\01\01"                ;; local type count
   470      "\7f"                      ;; i32
   471      "\41\00"                   ;; i32.const 0
   472      "\41\03"                   ;; i32.const 3
   473      "\36"                      ;; i32.store
   474      "\02"                      ;; alignment 2
   475      "\82\80\80\80\80\00"       ;; offset 2 with one byte too many
   476      "\0b"                      ;; end
   477    )
   478    "integer representation too long"
   479  )
   480  
   481  ;; Signed LEB128 must not be overlong
   482  (assert_malformed
   483    (module binary
   484      "\00asm" "\01\00\00\00"
   485      "\06\0b\01"                          ;; Global section with 1 entry
   486      "\7f\00"                             ;; i32, immutable
   487      "\41\80\80\80\80\80\00"              ;; i32.const 0 with one byte too many
   488      "\0b"                                ;; end
   489    )
   490    "integer representation too long"
   491  )
   492  (assert_malformed
   493    (module binary
   494      "\00asm" "\01\00\00\00"
   495      "\06\0b\01"                          ;; Global section with 1 entry
   496      "\7f\00"                             ;; i32, immutable
   497      "\41\ff\ff\ff\ff\ff\7f"              ;; i32.const -1 with one byte too many
   498      "\0b"                                ;; end
   499    )
   500    "integer representation too long"
   501  )
   502  
   503  (assert_malformed
   504    (module binary
   505      "\00asm" "\01\00\00\00"
   506      "\06\10\01"                          ;; Global section with 1 entry
   507      "\7e\00"                             ;; i64, immutable
   508      "\42\80\80\80\80\80\80\80\80\80\80\00"  ;; i64.const 0 with one byte too many
   509      "\0b"                                ;; end
   510    )
   511    "integer representation too long"
   512  )
   513  (assert_malformed
   514    (module binary
   515      "\00asm" "\01\00\00\00"
   516      "\06\10\01"                          ;; Global section with 1 entry
   517      "\7e\00"                             ;; i64, immutable
   518      "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\ff\7f"  ;; i64.const -1 with one byte too many
   519      "\0b"                                ;; end
   520    )
   521    "integer representation too long"
   522  )
   523  
   524  ;; Unsigned LEB128s zero-extend
   525  (assert_malformed
   526    (module binary
   527      "\00asm" "\01\00\00\00"
   528      "\05\07\01"                          ;; Memory section with 1 entry
   529      "\00\82\80\80\80\70"                 ;; no max, minimum 2 with unused bits set
   530    )
   531    "integer too large"
   532  )
   533  (assert_malformed
   534    (module binary
   535      "\00asm" "\01\00\00\00"
   536      "\05\07\01"                          ;; Memory section with 1 entry
   537      "\00\82\80\80\80\40"                 ;; no max, minimum 2 with some unused bits set
   538    )
   539    "integer too large"
   540  )
   541  (assert_malformed
   542    (module binary
   543      "\00asm" "\01\00\00\00"
   544      "\05\09\01"                          ;; Memory section with 1 entry
   545      "\01\82\00"                          ;; minimum 2
   546      "\82\80\80\80\10"                    ;; max 2 with unused bits set
   547    )
   548    "integer too large"
   549  )
   550  (assert_malformed
   551    (module binary
   552      "\00asm" "\01\00\00\00"
   553      "\05\09\01"                          ;; Memory section with 1 entry
   554      "\01\82\00"                          ;; minimum 2
   555      "\82\80\80\80\40"                    ;; max 2 with some unused bits set
   556    )
   557    "integer too large"
   558  )
   559  (assert_malformed
   560    (module binary
   561      "\00asm" "\01\00\00\00"
   562      "\05\03\01"                          ;; Memory section with 1 entry
   563      "\00\00"                             ;; no max, minimum 0
   564      "\0b\0a\01"                          ;; Data section with 1 entry
   565      "\80\80\80\80\10"                    ;; Memory index 0 with unused bits set
   566      "\41\00\0b\00"                       ;; (i32.const 0) with contents ""
   567    )
   568    "integer too large"
   569  )
   570  (assert_malformed
   571    (module binary
   572      "\00asm" "\01\00\00\00"
   573      "\04\04\01"                          ;; Table section with 1 entry
   574      "\70\00\00"                          ;; no max, minimum 0, funcref
   575      "\09\0a\01"                          ;; Element section with 1 entry
   576      "\80\80\80\80\10"                    ;; Table index 0 with unused bits set
   577      "\41\00\0b\00"                       ;; (i32.const 0) with no elements
   578    )
   579    "integer too large"
   580  )
   581  (assert_malformed
   582    (module binary
   583      "\00asm" "\01\00\00\00"
   584      "\00"                                ;; custom section
   585      "\83\80\80\80\10"                    ;; section size 3 with unused bits set
   586      "\01"                                ;; name byte count
   587      "1"                                  ;; name
   588      "2"                                  ;; sequence of bytes
   589    )
   590    "integer too large"
   591  )
   592  (assert_malformed
   593    (module binary
   594      "\00asm" "\01\00\00\00"
   595      "\00"                                ;; custom section
   596      "\09"                                ;; section size
   597      "\83\80\80\80\40"                    ;; name byte count 3 with unused bits set
   598      "123"                                ;; name
   599      "4"                                  ;; sequence of bytes
   600    )
   601    "integer too large"
   602  )
   603  (assert_malformed
   604    (module binary
   605      "\00asm" "\01\00\00\00"
   606      "\01\0b\01"                          ;; type section
   607      "\60"                                ;; func type
   608      "\82\80\80\80\10"                    ;; num params 2 with unused bits set
   609      "\7f\7e"                             ;; param type
   610      "\01"                                ;; num result
   611      "\7f"                                ;; result type
   612    )
   613    "integer too large"
   614  )
   615  (assert_malformed
   616    (module binary
   617      "\00asm" "\01\00\00\00"
   618      "\01\0b\01"                          ;; type section
   619      "\60"                                ;; func type
   620      "\02"                                ;; num params
   621      "\7f\7e"                             ;; param type
   622      "\81\80\80\80\40"                    ;; num result 1 with unused bits set
   623      "\7f"                                ;; result type
   624    )
   625    "integer too large"
   626  )
   627  (assert_malformed
   628    (module binary
   629      "\00asm" "\01\00\00\00"
   630      "\01\05\01"                          ;; type section
   631      "\60\01\7f\00"                       ;; function type
   632      "\02\1a\01"                          ;; import section
   633      "\88\80\80\80\10"                    ;; module name length 8 with unused bits set
   634      "\73\70\65\63\74\65\73\74"           ;; module name
   635      "\09"                                ;; entity name length
   636      "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   637      "\00"                                ;; import kind
   638      "\00"                                ;; import signature index
   639    )
   640    "integer too large"
   641  )
   642  (assert_malformed
   643    (module binary
   644      "\00asm" "\01\00\00\00"
   645      "\01\05\01"                          ;; type section
   646      "\60\01\7f\00"                       ;; function type
   647      "\02\1a\01"                          ;; import section
   648      "\08"                                ;; module name length
   649      "\73\70\65\63\74\65\73\74"           ;; module name
   650      "\89\80\80\80\40"                    ;; entity name length 9 with unused bits set
   651      "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   652      "\00"                                ;; import kind
   653      "\00"                                ;; import signature index
   654    )
   655    "integer too large"
   656  )
   657  (assert_malformed
   658  (module binary
   659    "\00asm" "\01\00\00\00"
   660    "\01\05\01"                          ;; type section
   661    "\60\01\7f\00"                       ;; function type
   662    "\02\1a\01"                          ;; import section
   663    "\08"                                ;; module name length
   664    "\73\70\65\63\74\65\73\74"           ;; module name
   665    "\09"                                ;; entity name length 9
   666    "\70\72\69\6e\74\5f\69\33\32"        ;; entity name
   667    "\00"                                ;; import kind
   668    "\80\80\80\80\10"                    ;; import signature index 0 with unused bits set
   669  )
   670    "integer too large"
   671  )
   672  (assert_malformed
   673    (module binary
   674      "\00asm" "\01\00\00\00"
   675      "\01\04\01"                          ;; type section
   676      "\60\00\00"                          ;; function type
   677      "\03\06\01"                          ;; function section
   678      "\80\80\80\80\10"                    ;; function 0 signature index with unused bits set
   679      "\0a\04\01"                          ;; code section
   680      "\02\00\0b"                          ;; function body
   681    )
   682    "integer too large"
   683  )
   684  
   685  (assert_malformed
   686    (module binary
   687      "\00asm" "\01\00\00\00"
   688      "\01\04\01"                          ;; type section
   689      "\60\00\00"                          ;; fun type
   690      "\03\02\01\00"                       ;; function section
   691      "\07\0a\01"                          ;; export section
   692      "\82\80\80\80\10"                    ;; string length 2 with unused bits set
   693      "\66\31"                             ;; export name f1
   694      "\00"                                ;; export kind
   695      "\00"                                ;; export func index
   696      "\0a\04\01"                          ;; code section
   697      "\02\00\0b"                          ;; function body
   698    )
   699    "integer too large"
   700  )
   701  (assert_malformed
   702    (module binary
   703      "\00asm" "\01\00\00\00"
   704      "\01\04\01"                          ;; type section
   705      "\60\00\00"                          ;; fun type
   706      "\03\02\01\00"                       ;; function section
   707      "\07\0a\01"                          ;; export section
   708      "\02"                                ;; string length 2
   709      "\66\31"                             ;; export name f1
   710      "\00"                                ;; export kind
   711      "\80\80\80\80\10"                    ;; export func index with unused bits set
   712      "\0a\04\01"                          ;; code section
   713      "\02\00\0b"                          ;; function body
   714    )
   715    "integer too large"
   716  )
   717  (assert_malformed
   718    (module binary
   719      "\00asm" "\01\00\00\00"
   720      "\01\04\01"                          ;; type section
   721      "\60\00\00"                          ;; fun type
   722      "\03\02\01\00"                       ;; function section
   723      "\0a"                                ;; code section
   724      "\08"                                ;; section size
   725      "\81\80\80\80\10"                    ;; num functions 1 with unused bits set
   726      "\02\00\0b"                          ;; function body
   727    )
   728    "integer too large"
   729  )
   730  (assert_malformed
   731    (module binary
   732      "\00asm" "\01\00\00\00"
   733      "\01\04\01\60\00\00"       ;; Type section
   734      "\03\02\01\00"             ;; Function section
   735      "\05\03\01\00\01"          ;; Memory section
   736      "\0a\10\01"                ;; Code section
   737      ;; function 0
   738      "\0e\01\01"                ;; local type count
   739      "\7f"                      ;; i32
   740      "\41\00"                   ;; i32.const 0
   741      "\28"                      ;; i32.load
   742      "\02"                      ;; alignment 2
   743      "\82\80\80\80\10"          ;; offset 2 with unused bits set
   744      "\1a"                      ;; drop
   745      "\0b"                      ;; end
   746    )
   747    "integer too large"
   748  )
   749  (assert_malformed
   750    (module binary
   751      "\00asm" "\01\00\00\00"
   752      "\01\04\01\60\00\00"       ;; Type section
   753      "\03\02\01\00"             ;; Function section
   754      "\05\03\01\00\01"          ;; Memory section
   755      "\0a\10\01"                ;; Code section
   756      ;; function 0
   757      "\0e\01\01"                ;; local type count
   758      "\7f"                      ;; i32
   759      "\41\00"                   ;; i32.const 0
   760      "\28"                      ;; i32.load
   761      "\02"                      ;; alignment 2
   762      "\82\80\80\80\40"          ;; offset 2 with some unused bits set
   763      "\1a"                      ;; drop
   764      "\0b"                      ;; end
   765    )
   766    "integer too large"
   767  )
   768  (assert_malformed
   769    (module binary
   770      "\00asm" "\01\00\00\00"
   771      "\01\04\01\60\00\00"       ;; Type section
   772      "\03\02\01\00"             ;; Function section
   773      "\05\03\01\00\01"          ;; Memory section
   774      "\0a\10\01"                ;; Code section
   775      "\0e\01\01"                ;; local type count
   776      "\7f"                      ;; i32
   777      "\41\00"                   ;; i32.const 0
   778      "\28"                      ;; i32.load
   779      "\82\80\80\80\10"          ;; alignment 2 with unused bits set
   780      "\00"                      ;; offset 0
   781      "\1a"                      ;; drop
   782      "\0b"                      ;; end
   783    )
   784    "integer too large"
   785  )
   786  (assert_malformed
   787    (module binary
   788      "\00asm" "\01\00\00\00"
   789      "\01\04\01\60\00\00"       ;; Type section
   790      "\03\02\01\00"             ;; Function section
   791      "\05\03\01\00\01"          ;; Memory section
   792      "\0a\10\01"                ;; Code section
   793      ;; function 0
   794      "\0e\01\01"                ;; local type count
   795      "\7f"                      ;; i32
   796      "\41\00"                   ;; i32.const 0
   797      "\28"                      ;; i32.load
   798      "\82\80\80\80\40"          ;; alignment 2 with some unused bits set
   799      "\00"                      ;; offset 0
   800      "\1a"                      ;; drop
   801      "\0b"                      ;; end
   802    )
   803    "integer too large"
   804  )
   805  (assert_malformed
   806    (module binary
   807      "\00asm" "\01\00\00\00"
   808      "\01\04\01\60\00\00"       ;; Type section
   809      "\03\02\01\00"             ;; Function section
   810      "\05\03\01\00\01"          ;; Memory section
   811      "\0a\11\01"                ;; Code section
   812      ;; function 0
   813      "\0f\01\01"                ;; local type count
   814      "\7f"                      ;; i32
   815      "\41\00"                   ;; i32.const 0
   816      "\41\03"                   ;; i32.const 3
   817      "\36"                      ;; i32.store
   818      "\82\80\80\80\10"          ;; alignment 2 with unused bits set
   819      "\03"                      ;; offset 3
   820      "\0b"                      ;; end
   821    )
   822    "integer too large"
   823  )
   824  (assert_malformed
   825    (module binary
   826      "\00asm" "\01\00\00\00"
   827      "\01\04\01\60\00\00"       ;; Type section
   828      "\03\02\01\00"             ;; Function section
   829      "\05\03\01\00\01"          ;; Memory section
   830      "\0a\11\01"                ;; Code section
   831      ;; function 0
   832      "\0f\01\01"                ;; local type count
   833      "\7f"                      ;; i32
   834      "\41\00"                   ;; i32.const 0
   835      "\41\03"                   ;; i32.const 3
   836      "\36"                      ;; i32.store
   837      "\82\80\80\80\40"          ;; alignment 2 with some unused bits set
   838      "\03"                      ;; offset 3
   839      "\0b"                      ;; end
   840    )
   841    "integer too large"
   842  )
   843  (assert_malformed
   844    (module binary
   845      "\00asm" "\01\00\00\00"
   846      "\01\04\01\60\00\00"       ;; Type section
   847      "\03\02\01\00"             ;; Function section
   848      "\05\03\01\00\01"          ;; Memory section
   849      "\0a\11\01"                ;; Code section
   850      ;; function 0
   851      "\0f\01\01"                ;; local type count
   852      "\7f"                      ;; i32
   853      "\41\00"                   ;; i32.const 0
   854      "\41\03"                   ;; i32.const 3
   855      "\36"                      ;; i32.store
   856      "\02"                      ;; alignment 2
   857      "\82\80\80\80\10"          ;; offset 2 with unused bits set
   858      "\0b"                      ;; end
   859    )
   860    "integer too large"
   861  )
   862  (assert_malformed
   863    (module binary
   864      "\00asm" "\01\00\00\00"
   865      "\01\04\01\60\00\00"       ;; Type section
   866      "\03\02\01\00"             ;; Function section
   867      "\05\03\01\00\01"          ;; Memory section
   868      "\0a\11\01"                ;; Code section
   869  
   870      ;; function 0
   871      "\0f\01\01"                ;; local type count
   872      "\7f"                      ;; i32
   873      "\41\00"                   ;; i32.const 0
   874      "\41\03"                   ;; i32.const 3
   875      "\36"                      ;; i32.store
   876      "\02"                      ;; alignment 2
   877      "\82\80\80\80\40"          ;; offset 2 with some unused bits set
   878      "\0b"                      ;; end
   879    )
   880    "integer too large"
   881  )
   882  
   883  ;; Signed LEB128s sign-extend
   884  (assert_malformed
   885    (module binary
   886      "\00asm" "\01\00\00\00"
   887      "\06\0a\01"                          ;; Global section with 1 entry
   888      "\7f\00"                             ;; i32, immutable
   889      "\41\80\80\80\80\70"                 ;; i32.const 0 with unused bits set
   890      "\0b"                                ;; end
   891    )
   892    "integer too large"
   893  )
   894  (assert_malformed
   895    (module binary
   896      "\00asm" "\01\00\00\00"
   897      "\06\0a\01"                          ;; Global section with 1 entry
   898      "\7f\00"                             ;; i32, immutable
   899      "\41\ff\ff\ff\ff\0f"                 ;; i32.const -1 with unused bits unset
   900      "\0b"                                ;; end
   901    )
   902    "integer too large"
   903  )
   904  (assert_malformed
   905    (module binary
   906      "\00asm" "\01\00\00\00"
   907      "\06\0a\01"                          ;; Global section with 1 entry
   908      "\7f\00"                             ;; i32, immutable
   909      "\41\80\80\80\80\1f"                 ;; i32.const 0 with some unused bits set
   910      "\0b"                                ;; end
   911    )
   912    "integer too large"
   913  )
   914  (assert_malformed
   915    (module binary
   916      "\00asm" "\01\00\00\00"
   917      "\06\0a\01"                          ;; Global section with 1 entry
   918      "\7f\00"                             ;; i32, immutable
   919      "\41\ff\ff\ff\ff\4f"                 ;; i32.const -1 with some unused bits unset
   920      "\0b"                                ;; end
   921    )
   922    "integer too large"
   923  )
   924  
   925  (assert_malformed
   926    (module binary
   927      "\00asm" "\01\00\00\00"
   928      "\06\0f\01"                          ;; Global section with 1 entry
   929      "\7e\00"                             ;; i64, immutable
   930      "\42\80\80\80\80\80\80\80\80\80\7e"  ;; i64.const 0 with unused bits set
   931      "\0b"                                ;; end
   932    )
   933    "integer too large"
   934  )
   935  (assert_malformed
   936    (module binary
   937      "\00asm" "\01\00\00\00"
   938      "\06\0f\01"                          ;; Global section with 1 entry
   939      "\7e\00"                             ;; i64, immutable
   940      "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\01"  ;; i64.const -1 with unused bits unset
   941      "\0b"                                ;; end
   942    )
   943    "integer too large"
   944  )
   945  (assert_malformed
   946    (module binary
   947      "\00asm" "\01\00\00\00"
   948      "\06\0f\01"                          ;; Global section with 1 entry
   949      "\7e\00"                             ;; i64, immutable
   950      "\42\80\80\80\80\80\80\80\80\80\02"  ;; i64.const 0 with some unused bits set
   951      "\0b"                                ;; end
   952    )
   953    "integer too large"
   954  )
   955  (assert_malformed
   956    (module binary
   957      "\00asm" "\01\00\00\00"
   958      "\06\0f\01"                          ;; Global section with 1 entry
   959      "\7e\00"                             ;; i64, immutable
   960      "\42\ff\ff\ff\ff\ff\ff\ff\ff\ff\41"  ;; i64.const -1 with some unused bits unset
   961      "\0b"                                ;; end
   962    )
   963    "integer too large"
   964  )
   965  
   966  
   967  (module binary
   968    "\00asm" "\01\00\00\00"
   969    "\01\04\01"                          ;; type section
   970    "\60\00\00"                          ;; empty function type
   971    "\03\02\01"                          ;; function section
   972    "\00"                                ;; function 0, type 0
   973    "\0a\1b\01\19"                       ;; code section
   974    "\00"                                ;; no locals
   975    "\00"                                ;; unreachable
   976    "\fc\80\00"                          ;; i32_trunc_sat_f32_s with 2 bytes
   977    "\00"                                ;; unreachable
   978    "\fc\81\80\00"                       ;; i32_trunc_sat_f32_u with 3 bytes
   979    "\00"                                ;; unreachable
   980    "\fc\86\80\80\00"                    ;; i64_trunc_sat_f64_s with 4 bytes
   981    "\00"                                ;; unreachable
   982    "\fc\87\80\80\80\00"                 ;; i64_trunc_sat_f64_u with 5 bytes
   983    "\00"                                ;; unreachable
   984    "\0b"                                ;; end
   985  )
   986  
   987  (assert_malformed
   988    (module binary
   989      "\00asm" "\01\00\00\00"
   990      "\01\04\01"                          ;; type section
   991      "\60\00\00"                          ;; empty function type
   992      "\03\02\01"                          ;; function section
   993      "\00"                                ;; function 0, type 0
   994      "\0a\0d\01\0b"                       ;; code section
   995      "\00"                                ;; no locals
   996      "\00"                                ;; unreachable
   997      "\fc\87\80\80\80\80\00"              ;; i64_trunc_sat_f64_u with 6 bytes
   998      "\00"                                ;; unreachable
   999      "\0b"                                ;; end
  1000    )
  1001    "integer representation too long"
  1002  )