OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/wasm/module-decoder.h" | 7 #include "src/wasm/module-decoder.h" |
8 #include "src/wasm/wasm-macro-gen.h" | 8 #include "src/wasm/wasm-macro-gen.h" |
9 #include "src/wasm/wasm-opcodes.h" | 9 #include "src/wasm/wasm-opcodes.h" |
10 | 10 |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 EXPECT_EQ(4, function->local_i64_count); | 925 EXPECT_EQ(4, function->local_i64_count); |
926 EXPECT_EQ(5, function->local_f32_count); | 926 EXPECT_EQ(5, function->local_f32_count); |
927 EXPECT_EQ(6, function->local_f64_count); | 927 EXPECT_EQ(6, function->local_f64_count); |
928 EXPECT_FALSE(function->external); | 928 EXPECT_FALSE(function->external); |
929 EXPECT_FALSE(function->exported); | 929 EXPECT_FALSE(function->exported); |
930 } | 930 } |
931 | 931 |
932 if (result.val) delete result.val; | 932 if (result.val) delete result.val; |
933 } | 933 } |
934 | 934 |
935 | 935 TEST_F(WasmModuleVerifyTest, UnknownSectionNoLen) { |
936 TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) { | |
937 const byte data[] = { | 936 const byte data[] = { |
938 kDeclWLL, // section without length. | 937 kMaxModuleSectionCode, // unknown section without length. |
939 }; | 938 }; |
940 EXPECT_FAILURE(data); | 939 EXPECT_FAILURE(data); |
941 } | 940 } |
942 | 941 |
943 | 942 TEST_F(WasmModuleVerifyTest, UnknownSectionEmpty) { |
944 TEST_F(WasmModuleVerifyTest, WLLSectionEmpty) { | 943 for (int i = 0; i < 255 - kMaxModuleSectionCode; ++i) { |
945 static const byte data[] = { | 944 const byte data[] = { |
946 kDeclWLL, 0, // empty section | 945 byte(kMaxModuleSectionCode + i), 0, // empty unknown section |
947 }; | 946 }; |
948 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 947 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
949 EXPECT_TRUE(result.ok()); | 948 EXPECT_TRUE(result.ok()); |
950 if (result.val) delete result.val; | 949 if (result.val) delete result.val; |
| 950 } |
951 } | 951 } |
952 | 952 |
953 | 953 TEST_F(WasmModuleVerifyTest, UnknownSectionOne) { |
954 TEST_F(WasmModuleVerifyTest, WLLSectionOne) { | |
955 static const byte data[] = { | 954 static const byte data[] = { |
956 kDeclWLL, | 955 kMaxModuleSectionCode, |
957 1, // LEB128 1 | 956 1, // LEB128 1 |
958 0, // one byte section | 957 0, // one byte section |
959 }; | 958 }; |
960 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 959 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
961 EXPECT_TRUE(result.ok()); | 960 EXPECT_TRUE(result.ok()); |
962 if (result.val) delete result.val; | 961 if (result.val) delete result.val; |
963 } | 962 } |
964 | 963 |
965 | 964 TEST_F(WasmModuleVerifyTest, UnknownSectionTen) { |
966 TEST_F(WasmModuleVerifyTest, WLLSectionTen) { | |
967 static const byte data[] = { | 965 static const byte data[] = { |
968 kDeclWLL, | 966 kMaxModuleSectionCode, |
969 10, // LEB128 10 | 967 10, // LEB128 10 |
970 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section | 968 1, |
| 969 2, |
| 970 3, |
| 971 4, |
| 972 5, |
| 973 6, |
| 974 7, |
| 975 8, |
| 976 9, |
| 977 10, // 10 byte section |
971 }; | 978 }; |
972 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 979 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
973 EXPECT_TRUE(result.ok()); | 980 EXPECT_TRUE(result.ok()); |
974 if (result.val) delete result.val; | 981 if (result.val) delete result.val; |
975 } | 982 } |
976 | 983 |
977 | 984 TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) { |
978 TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) { | |
979 static const byte data[] = { | 985 static const byte data[] = { |
980 kDeclWLL, | 986 kMaxModuleSectionCode, |
981 11, // LEB128 11 | 987 11, // LEB128 11 |
982 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section | 988 1, |
| 989 2, |
| 990 3, |
| 991 4, |
| 992 5, |
| 993 6, |
| 994 7, |
| 995 8, |
| 996 9, |
| 997 10, // 10 byte section |
983 }; | 998 }; |
984 EXPECT_FAILURE(data); | 999 EXPECT_FAILURE(data); |
985 } | 1000 } |
986 | 1001 |
987 | 1002 TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) { |
988 TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) { | |
989 static const byte data[] = { | 1003 static const byte data[] = { |
990 kDeclWLL, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff | 1004 kMaxModuleSectionCode, |
991 1, 2, 3, 4, // 4 byte section | 1005 0xff, |
| 1006 0xff, |
| 1007 0xff, |
| 1008 0xff, |
| 1009 0x0f, // LEB128 0xffffffff |
| 1010 1, |
| 1011 2, |
| 1012 3, |
| 1013 4, // 4 byte section |
992 }; | 1014 }; |
993 EXPECT_FAILURE(data); | 1015 EXPECT_FAILURE(data); |
994 } | 1016 } |
995 | 1017 |
996 | 1018 TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) { |
997 TEST_F(WasmModuleVerifyTest, WLLSectionLoop) { | |
998 // Would infinite loop decoding if wrapping and allowed. | 1019 // Would infinite loop decoding if wrapping and allowed. |
999 static const byte data[] = { | 1020 static const byte data[] = { |
1000 kDeclWLL, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa | 1021 kMaxModuleSectionCode, |
1001 1, 2, 3, 4, // 4 byte section | 1022 0xfa, |
| 1023 0xff, |
| 1024 0xff, |
| 1025 0xff, |
| 1026 0x0f, // LEB128 0xfffffffa |
| 1027 1, |
| 1028 2, |
| 1029 3, |
| 1030 4, // 4 byte section |
1002 }; | 1031 }; |
1003 EXPECT_FAILURE(data); | 1032 EXPECT_FAILURE(data); |
1004 } | 1033 } |
1005 | 1034 |
| 1035 TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) { |
| 1036 static const byte data[] = { |
| 1037 kMaxModuleSectionCode, |
| 1038 1, // LEB128 1 |
| 1039 0, // one byte section |
| 1040 kDeclGlobals, |
| 1041 1, |
| 1042 0, |
| 1043 0, |
| 1044 0, |
| 1045 0, // name offset |
| 1046 kMemI32, // memory type |
| 1047 0, // exported |
| 1048 }; |
| 1049 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
| 1050 EXPECT_TRUE(result.ok()); |
| 1051 |
| 1052 EXPECT_EQ(1, result.val->globals.size()); |
| 1053 EXPECT_EQ(0, result.val->functions.size()); |
| 1054 EXPECT_EQ(0, result.val->data_segments.size()); |
| 1055 |
| 1056 WasmGlobal* global = &result.val->globals.back(); |
| 1057 |
| 1058 EXPECT_EQ(0, global->name_offset); |
| 1059 EXPECT_EQ(MachineType::Int32(), global->type); |
| 1060 EXPECT_EQ(0, global->offset); |
| 1061 EXPECT_FALSE(global->exported); |
| 1062 |
| 1063 if (result.val) delete result.val; |
| 1064 } |
| 1065 |
1006 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { | 1066 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { |
1007 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0}; | 1067 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0}; |
1008 EXPECT_VERIFIES(data); | 1068 EXPECT_VERIFIES(data); |
1009 } | 1069 } |
1010 | 1070 |
1011 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) { | 1071 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) { |
1012 static const byte data[] = {kDeclImportTable, 0}; | 1072 static const byte data[] = {kDeclImportTable, 0}; |
1013 EXPECT_FAILURE(data); | 1073 EXPECT_FAILURE(data); |
1014 } | 1074 } |
1015 | 1075 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 for (int length = 13; length < sizeof(data); length++) { | 1207 for (int length = 13; length < sizeof(data); length++) { |
1148 ModuleResult result = DecodeModule(data, data + length); | 1208 ModuleResult result = DecodeModule(data, data + length); |
1149 EXPECT_FALSE(result.ok()); | 1209 EXPECT_FALSE(result.ok()); |
1150 if (result.val) delete result.val; | 1210 if (result.val) delete result.val; |
1151 } | 1211 } |
1152 } | 1212 } |
1153 | 1213 |
1154 } // namespace wasm | 1214 } // namespace wasm |
1155 } // namespace internal | 1215 } // namespace internal |
1156 } // namespace v8 | 1216 } // namespace v8 |
OLD | NEW |