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

Unified 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: Fix limit type Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/module-decoder-unittest.cc
diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc
index 77d413acedff701830be6007cafc5abdd4c81e04..cab235f61b8074208751a9dbbf2663b749ca35fd 100644
--- a/test/unittests/wasm/module-decoder-unittest.cc
+++ b/test/unittests/wasm/module-decoder-unittest.cc
@@ -932,28 +932,27 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
if (result.val) delete result.val;
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionNoLen) {
const byte data[] = {
- kDeclWLL, // section without length.
+ kMaxModuleSectionCode, // unknown section without length.
};
EXPECT_FAILURE(data);
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionEmpty) {
- static const byte data[] = {
- kDeclWLL, 0, // empty section
- };
- ModuleResult result = DecodeModule(data, data + arraysize(data));
- EXPECT_TRUE(result.ok());
- if (result.val) delete result.val;
+TEST_F(WasmModuleVerifyTest, UnknownSectionEmpty) {
+ for (int i = 0; i < 255 - kMaxModuleSectionCode; ++i) {
+ const byte data[] = {
+ byte(kMaxModuleSectionCode + i), 0, // empty unknown section
+ };
+ ModuleResult result = DecodeModule(data, data + arraysize(data));
+ EXPECT_TRUE(result.ok());
+ if (result.val) delete result.val;
+ }
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionOne) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionOne) {
static const byte data[] = {
- kDeclWLL,
+ kMaxModuleSectionCode,
1, // LEB128 1
0, // one byte section
};
@@ -962,47 +961,108 @@ TEST_F(WasmModuleVerifyTest, WLLSectionOne) {
if (result.val) delete result.val;
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionTen) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionTen) {
static const byte data[] = {
- kDeclWLL,
- 10, // LEB128 10
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
+ kMaxModuleSectionCode,
+ 10, // LEB128 10
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10, // 10 byte section
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.val) delete result.val;
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
static const byte data[] = {
- kDeclWLL,
- 11, // LEB128 11
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
+ kMaxModuleSectionCode,
+ 11, // LEB128 11
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10, // 10 byte section
};
EXPECT_FAILURE(data);
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
static const byte data[] = {
- kDeclWLL, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff
- 1, 2, 3, 4, // 4 byte section
+ kMaxModuleSectionCode,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x0f, // LEB128 0xffffffff
+ 1,
+ 2,
+ 3,
+ 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionLoop) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) {
// Would infinite loop decoding if wrapping and allowed.
static const byte data[] = {
- kDeclWLL, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa
- 1, 2, 3, 4, // 4 byte section
+ kMaxModuleSectionCode,
+ 0xfa,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x0f, // LEB128 0xfffffffa
+ 1,
+ 2,
+ 3,
+ 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
+TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
+ static const byte data[] = {
+ kMaxModuleSectionCode,
+ 1, // LEB128 1
+ 0, // one byte section
+ kDeclGlobals,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0, // name offset
+ kMemI32, // memory type
+ 0, // exported
+ };
+ ModuleResult result = DecodeModule(data, data + arraysize(data));
+ EXPECT_TRUE(result.ok());
+
+ EXPECT_EQ(1, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(0, result.val->data_segments.size());
+
+ WasmGlobal* global = &result.val->globals.back();
+
+ EXPECT_EQ(0, global->name_offset);
+ EXPECT_EQ(MachineType::Int32(), global->type);
+ EXPECT_EQ(0, global->offset);
+ EXPECT_FALSE(global->exported);
+
+ if (result.val) delete result.val;
+}
+
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0};
EXPECT_VERIFIES(data);
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698