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

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: 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/wasm-module.h ('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
969 TEST_F(WasmModuleVerifyTest, WLLSectionTen) { 968 TEST_F(WasmModuleVerifyTest, UnknownSectionTen) {
970 static const byte data[] = { 969 static const byte data[] = {
971 kDeclWLL, 970 kMaxModuleSectionCode,
972 10, // LEB128 10 971 10, // LEB128 10
973 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section 972 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
974 }; 973 };
975 ModuleResult result = DecodeModule(data, data + arraysize(data)); 974 ModuleResult result = DecodeModule(data, data + arraysize(data));
976 EXPECT_TRUE(result.ok()); 975 EXPECT_TRUE(result.ok());
977 if (result.val) delete result.val; 976 if (result.val) delete result.val;
978 } 977 }
979 978
980 979
981 TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) { 980 TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
982 static const byte data[] = { 981 static const byte data[] = {
983 kDeclWLL, 982 kMaxModuleSectionCode,
984 11, // LEB128 11 983 11, // LEB128 11
985 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section 984 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
986 }; 985 };
987 EXPECT_FAILURE(data); 986 EXPECT_FAILURE(data);
988 } 987 }
989 988
990 989
991 TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) { 990 TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
992 static const byte data[] = { 991 static const byte data[] = {
993 kDeclWLL, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff 992 kMaxModuleSectionCode, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff
994 1, 2, 3, 4, // 4 byte section 993 1, 2, 3, 4, // 4 byte section
995 }; 994 };
996 EXPECT_FAILURE(data); 995 EXPECT_FAILURE(data);
997 } 996 }
998 997
999 998
1000 TEST_F(WasmModuleVerifyTest, WLLSectionLoop) { 999 TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) {
1001 // Would infinite loop decoding if wrapping and allowed. 1000 // Would infinite loop decoding if wrapping and allowed.
1002 static const byte data[] = { 1001 static const byte data[] = {
1003 kDeclWLL, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa 1002 kMaxModuleSectionCode, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa
1004 1, 2, 3, 4, // 4 byte section 1003 1, 2, 3, 4, // 4 byte section
1005 }; 1004 };
1006 EXPECT_FAILURE(data); 1005 EXPECT_FAILURE(data);
1007 } 1006 }
1008 1007
1008 TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
1009 static const byte data[] = {
1010 kMaxModuleSectionCode,
1011 1, // LEB128 1
1012 0, // one byte section
1013 kDeclGlobals,
1014 1,
1015 0,
1016 0,
1017 0,
1018 0, // name offset
1019 kMemI32, // memory type
1020 0, // exported
1021 };
1022 ModuleResult result = DecodeModule(data, data + arraysize(data));
1023 EXPECT_TRUE(result.ok());
1024
1025 EXPECT_EQ(1, result.val->globals->size());
1026 EXPECT_EQ(0, result.val->functions->size());
1027 EXPECT_EQ(0, result.val->data_segments->size());
1028
1029 WasmGlobal* global = &result.val->globals->back();
1030
1031 EXPECT_EQ(0, global->name_offset);
1032 EXPECT_EQ(MachineType::Int32(), global->type);
1033 EXPECT_EQ(0, global->offset);
1034 EXPECT_FALSE(global->exported);
1035
1036 if (result.val) delete result.val;
1037 }
1038
1009 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { 1039 TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
1010 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0}; 1040 static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0};
1011 EXPECT_VERIFIES(data); 1041 EXPECT_VERIFIES(data);
1012 } 1042 }
1013 1043
1014 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) { 1044 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) {
1015 static const byte data[] = {kDeclImportTable, 0}; 1045 static const byte data[] = {kDeclImportTable, 0};
1016 EXPECT_FAILURE(data); 1046 EXPECT_FAILURE(data);
1017 } 1047 }
1018 1048
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 for (size_t length = 5; length < sizeof(data); length++) { 1111 for (size_t length = 5; length < sizeof(data); length++) {
1082 ModuleResult result = DecodeModule(data, data + length); 1112 ModuleResult result = DecodeModule(data, data + length);
1083 EXPECT_FALSE(result.ok()); 1113 EXPECT_FALSE(result.ok());
1084 if (result.val) delete result.val; 1114 if (result.val) delete result.val;
1085 } 1115 }
1086 } 1116 }
1087 1117
1088 } // namespace wasm 1118 } // namespace wasm
1089 } // namespace internal 1119 } // namespace internal
1090 } // namespace v8 1120 } // namespace v8
OLDNEW
« src/wasm/wasm-module.h ('K') | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698