|
864 | 864 | (assert_trap (invoke "store" (i32.const 65532) (i64.const -1)) "out of bounds memory access")
|
865 | 865 | ;; No memory was changed
|
866 | 866 | (assert_return (invoke "load" (i32.const 65532)) (i32.const 0))
|
| 867 | + |
| 868 | +;; Test invalid alignment values that may cause overflow when parsed. |
| 869 | +;; These use the binary format, because it stores alignment as a base-2 exponent. |
| 870 | + |
| 871 | +;; Signed 32-bit overflow |
| 872 | +(assert_invalid |
| 873 | + (module binary |
| 874 | + "\00asm" "\01\00\00\00" |
| 875 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 876 | + "\03\02\01\00" ;; Function section: 1 function |
| 877 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 878 | + "\0a\0a\01" ;; Code section: 1 function |
| 879 | + |
| 880 | + ;; function 0 |
| 881 | + "\08\00" |
| 882 | + "\41\00" ;; i32.const 0 |
| 883 | + "\28\1f\00" ;; i32.load offset=0 align=2**31 |
| 884 | + "\1a" ;; drop |
| 885 | + "\0b" ;; end |
| 886 | + ) |
| 887 | + "alignment must not be larger than natural" |
| 888 | +) |
| 889 | + |
| 890 | +;; Unsigned 32-bit overflow |
| 891 | +(assert_malformed |
| 892 | + (module binary |
| 893 | + "\00asm" "\01\00\00\00" |
| 894 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 895 | + "\03\02\01\00" ;; Function section: 1 function |
| 896 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 897 | + "\0a\0a\01" ;; Code section: 1 function |
| 898 | + |
| 899 | + ;; function 0 |
| 900 | + "\08\00" |
| 901 | + "\41\00" ;; i32.const 0 |
| 902 | + "\28\20\00" ;; i32.load offset=0 align=2**32 |
| 903 | + "\1a" ;; drop |
| 904 | + "\0b" ;; end |
| 905 | + ) |
| 906 | + "malformed memop alignment" |
| 907 | +) |
| 908 | + |
| 909 | +;; 32-bit out of range |
| 910 | +(assert_malformed |
| 911 | + (module binary |
| 912 | + "\00asm" "\01\00\00\00" |
| 913 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 914 | + "\03\02\01\00" ;; Function section: 1 function |
| 915 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 916 | + "\0a\0a\01" ;; Code section: 1 function |
| 917 | + |
| 918 | + ;; function 0 |
| 919 | + "\08\00" |
| 920 | + "\41\00" ;; i32.const 0 |
| 921 | + "\28\21\00" ;; i32.load offset=0 align=2**33 |
| 922 | + "\1a" ;; drop |
| 923 | + "\0b" ;; end |
| 924 | + ) |
| 925 | + "malformed memop alignment" |
| 926 | +) |
| 927 | + |
| 928 | +;; Signed 64-bit overflow |
| 929 | +(assert_malformed |
| 930 | + (module binary |
| 931 | + "\00asm" "\01\00\00\00" |
| 932 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 933 | + "\03\02\01\00" ;; Function section: 1 function |
| 934 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 935 | + "\0a\0a\01" ;; Code section: 1 function |
| 936 | + |
| 937 | + ;; function 0 |
| 938 | + "\08\00" |
| 939 | + "\41\00" ;; i32.const 0 |
| 940 | + "\28\3f\00" ;; i32.load offset=0 align=2**63 |
| 941 | + "\1a" ;; drop |
| 942 | + "\0b" ;; end |
| 943 | + ) |
| 944 | + "malformed memop alignment" |
| 945 | +) |
| 946 | + |
| 947 | +;; Unsigned 64-bit overflow |
| 948 | +(assert_invalid |
| 949 | + (module binary |
| 950 | + "\00asm" "\01\00\00\00" |
| 951 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 952 | + "\03\02\01\00" ;; Function section: 1 function |
| 953 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 954 | + "\0a\0a\01" ;; Code section: 1 function |
| 955 | + |
| 956 | + ;; function 0 |
| 957 | + "\08\00" |
| 958 | + "\41\00" ;; i32.const 0 |
| 959 | + "\28\40\00" ;; i32.load offset=0 align=2**64 (parsed as align=0, memidx present) |
| 960 | + "\1a" ;; drop |
| 961 | + "\0b" ;; end |
| 962 | + ) |
| 963 | + "type mismatch" |
| 964 | +) |
| 965 | + |
| 966 | +;; 64-bit out of range |
| 967 | +(assert_invalid |
| 968 | + (module binary |
| 969 | + "\00asm" "\01\00\00\00" |
| 970 | + "\01\04\01\60\00\00" ;; Type section: 1 type |
| 971 | + "\03\02\01\00" ;; Function section: 1 function |
| 972 | + "\05\03\01\00\01" ;; Memory section: 1 memory |
| 973 | + "\0a\0a\01" ;; Code section: 1 function |
| 974 | + |
| 975 | + ;; function 0 |
| 976 | + "\08\00" |
| 977 | + "\41\00" ;; i32.const 0 |
| 978 | + "\28\41\00" ;; i32.load offset=0 align=2**65 (parsed as align=1, memidx present) |
| 979 | + "\1a" ;; drop |
| 980 | + "\0b" ;; end |
| 981 | + ) |
| 982 | + "type mismatch" |
| 983 | +) |
0 commit comments