Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: test/unittests/wasm/module-decoder-unittest.cc

Issue 1743773002: WebAssembly: skip unknown sections, add names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git cl format Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/wasm/module-decoder.cc ('K') | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-opcodes.h" 8 #include "src/wasm/wasm-opcodes.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 EXPECT_EQ(4, function->local_i64_count); 928 EXPECT_EQ(4, function->local_i64_count);
929 EXPECT_EQ(5, function->local_f32_count); 929 EXPECT_EQ(5, function->local_f32_count);
930 EXPECT_EQ(6, function->local_f64_count); 930 EXPECT_EQ(6, function->local_f64_count);
931 EXPECT_FALSE(function->external); 931 EXPECT_FALSE(function->external);
932 EXPECT_FALSE(function->exported); 932 EXPECT_FALSE(function->exported);
933 } 933 }
934 934
935 if (result.val) delete result.val; 935 if (result.val) delete result.val;
936 } 936 }
937 937
938 938 TEST_F(WasmModuleVerifyTest, UnknownSectionNoLen) {
939 TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) {
940 const byte data[] = { 939 const byte data[] = {
941 kDeclWLL, // section without length. 940 kMaxModuleSectionCode, // unknown section without length.
942 }; 941 };
943 EXPECT_FAILURE(data); 942 EXPECT_FAILURE(data);
944 } 943 }
945 944
946 945 TEST_F(WasmModuleVerifyTest, UnknownSectionEmpty) {
947 TEST_F(WasmModuleVerifyTest, WLLSectionEmpty) { 946 for (int i = 0; i < 255 - kMaxModuleSectionCode; ++i) {
948 static const byte data[] = { 947 const byte data[] = {
949 kDeclWLL, 0, // empty section 948 byte(kMaxModuleSectionCode + i), 0, // empty unknown section
950 }; 949 };
951 ModuleResult result = DecodeModule(data, data + arraysize(data)); 950 ModuleResult result = DecodeModule(data, data + arraysize(data));
952 EXPECT_TRUE(result.ok()); 951 EXPECT_TRUE(result.ok());
953 if (result.val) delete result.val; 952 if (result.val) delete result.val;
953 }
954 } 954 }
955 955
956 956 TEST_F(WasmModuleVerifyTest, UnknownSectionOne) {
957 TEST_F(WasmModuleVerifyTest, WLLSectionOne) {
958 static const byte data[] = { 957 static const byte data[] = {
959 kDeclWLL, 958 kMaxModuleSectionCode,
960 1, // LEB128 1 959 1, // LEB128 1
961 0, // one byte section 960 0, // one byte section
962 }; 961 };
963 ModuleResult result = DecodeModule(data, data + arraysize(data)); 962 ModuleResult result = DecodeModule(data, data + arraysize(data));
964 EXPECT_TRUE(result.ok()); 963 EXPECT_TRUE(result.ok());
965 if (result.val) delete result.val; 964 if (result.val) delete result.val;
966 } 965 }
967 966
968 967 TEST_F(WasmModuleVerifyTest, UnknownSectionTen) {
969 TEST_F(WasmModuleVerifyTest, WLLSectionTen) {
970 static const byte data[] = { 968 static const byte data[] = {
971 kDeclWLL, 969 kMaxModuleSectionCode,
972 10, // LEB128 10 970 10, // LEB128 10
973 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section 971 1,
972 2,
973 3,
974 4,
975 5,
976 6,
977 7,
978 8,
979 9,
980 10, // 10 byte section
974 }; 981 };
975 ModuleResult result = DecodeModule(data, data + arraysize(data)); 982 ModuleResult result = DecodeModule(data, data + arraysize(data));
976 EXPECT_TRUE(result.ok()); 983 EXPECT_TRUE(result.ok());
977 if (result.val) delete result.val; 984 if (result.val) delete result.val;
978 } 985 }
979 986
980 987 TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
981 TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) {
982 static const byte data[] = { 988 static const byte data[] = {
983 kDeclWLL, 989 kMaxModuleSectionCode,
984 11, // LEB128 11 990 11, // LEB128 11
985 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section 991 1,
992 2,
993 3,
994 4,
995 5,
996 6,
997 7,
998 8,
999 9,
1000 10, // 10 byte section
986 }; 1001 };
987 EXPECT_FAILURE(data); 1002 EXPECT_FAILURE(data);
988 } 1003 }
989 1004
990 1005 TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
991 TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) {
992 static const byte data[] = { 1006 static const byte data[] = {
993 kDeclWLL, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff 1007 kMaxModuleSectionCode,
994 1, 2, 3, 4, // 4 byte section 1008 0xff,
1009 0xff,
1010 0xff,
1011 0xff,
1012 0x0f, // LEB128 0xffffffff
1013 1,
1014 2,
1015 3,
1016 4, // 4 byte section
995 }; 1017 };
996 EXPECT_FAILURE(data); 1018 EXPECT_FAILURE(data);
997 } 1019 }
998 1020
999 1021 TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) {
1000 TEST_F(WasmModuleVerifyTest, WLLSectionLoop) {
1001 // Would infinite loop decoding if wrapping and allowed. 1022 // Would infinite loop decoding if wrapping and allowed.
1002 static const byte data[] = { 1023 static const byte data[] = {
1003 kDeclWLL, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa 1024 kMaxModuleSectionCode,
1004 1, 2, 3, 4, // 4 byte section 1025 0xfa,
1026 0xff,
1027 0xff,
1028 0xff,
1029 0x0f, // LEB128 0xfffffffa
1030 1,
1031 2,
1032 3,
1033 4, // 4 byte section
1005 }; 1034 };
1006 EXPECT_FAILURE(data); 1035 EXPECT_FAILURE(data);
1007 } 1036 }
1008 1037
1038 TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
1039 static const byte data[] = {
1040 kMaxModuleSectionCode,
1041 1, // LEB128 1
1042 0, // one byte section
1043 kDeclGlobals,
1044 1,
1045 0,
1046 0,
1047 0,
1048 0, // name offset
1049 kMemI32, // memory type
1050 0, // exported
1051 };
1052 ModuleResult result = DecodeModule(data, data + arraysize(data));
1053 EXPECT_TRUE(result.ok());
1054
1055 EXPECT_EQ(1, result.val->globals->size());
1056 EXPECT_EQ(0, result.val->functions->size());
1057 EXPECT_EQ(0, result.val->data_segments->size());
1058
1059 WasmGlobal* global = &result.val->globals->back();
1060
1061 EXPECT_EQ(0, global->name_offset);
1062 EXPECT_EQ(MachineType::Int32(), global->type);
1063 EXPECT_EQ(0, global->offset);
1064 EXPECT_FALSE(global->exported);
1065
1066 if (result.val) delete result.val;
1067 }
1068
1009 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { 1069 TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
1010 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0}; 1070 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0};
1011 EXPECT_VERIFIES(data); 1071 EXPECT_VERIFIES(data);
1012 } 1072 }
1013 1073
1014 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) { 1074 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) {
1015 static const byte data[] = {kDeclImportTable, 0}; 1075 static const byte data[] = {kDeclImportTable, 0};
1016 EXPECT_FAILURE(data); 1076 EXPECT_FAILURE(data);
1017 } 1077 }
1018 1078
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 for (size_t length = 5; length < sizeof(data); length++) { 1141 for (size_t length = 5; length < sizeof(data); length++) {
1082 ModuleResult result = DecodeModule(data, data + length); 1142 ModuleResult result = DecodeModule(data, data + length);
1083 EXPECT_FALSE(result.ok()); 1143 EXPECT_FALSE(result.ok());
1084 if (result.val) delete result.val; 1144 if (result.val) delete result.val;
1085 } 1145 }
1086 } 1146 }
1087 1147
1088 } // namespace wasm 1148 } // namespace wasm
1089 } // namespace internal 1149 } // namespace internal
1090 } // namespace v8 1150 } // namespace v8
OLDNEW
« src/wasm/module-decoder.cc ('K') | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698