| 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/handles.h" | 7 #include "src/handles.h" |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
| 10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 class WasmModuleVerifyTest : public TestWithIsolateAndZone { | 136 class WasmModuleVerifyTest : public TestWithIsolateAndZone { |
| 137 public: | 137 public: |
| 138 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { | 138 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { |
| 139 // Add the WASM magic and version number automatically. | 139 // Add the WASM magic and version number automatically. |
| 140 size_t size = static_cast<size_t>(module_end - module_start); | 140 size_t size = static_cast<size_t>(module_end - module_start); |
| 141 byte header[] = {WASM_MODULE_HEADER}; | 141 byte header[] = {WASM_MODULE_HEADER}; |
| 142 size_t total = sizeof(header) + size; | 142 size_t total = sizeof(header) + size; |
| 143 auto temp = new byte[total]; | 143 auto temp = new byte[total]; |
| 144 memcpy(temp, header, sizeof(header)); | 144 memcpy(temp, header, sizeof(header)); |
| 145 memcpy(temp + sizeof(header), module_start, size); | 145 memcpy(temp + sizeof(header), module_start, size); |
| 146 ModuleResult result = DecodeWasmModule(isolate(), zone(), temp, | 146 ModuleResult result = |
| 147 temp + total, false, kWasmOrigin); | 147 DecodeWasmModule(isolate(), temp, temp + total, false, kWasmOrigin); |
| 148 delete[] temp; | 148 delete[] temp; |
| 149 return result; | 149 return result; |
| 150 } | 150 } |
| 151 ModuleResult DecodeModuleNoHeader(const byte* module_start, | 151 ModuleResult DecodeModuleNoHeader(const byte* module_start, |
| 152 const byte* module_end) { | 152 const byte* module_end) { |
| 153 return DecodeWasmModule(isolate(), zone(), module_start, module_end, false, | 153 return DecodeWasmModule(isolate(), module_start, module_end, false, |
| 154 kWasmOrigin); | 154 kWasmOrigin); |
| 155 } | 155 } |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 TEST_F(WasmModuleVerifyTest, WrongMagic) { | 158 TEST_F(WasmModuleVerifyTest, WrongMagic) { |
| 159 for (uint32_t x = 1; x; x <<= 1) { | 159 for (uint32_t x = 1; x; x <<= 1) { |
| 160 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; | 160 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; |
| 161 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); | 161 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); |
| 162 EXPECT_FALSE(result.ok()); | 162 EXPECT_FALSE(result.ok()); |
| 163 if (result.val) delete result.val; | 163 if (result.val) delete result.val; |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- | 1292 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- |
| 1293 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- | 1293 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- |
| 1294 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- | 1294 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- |
| 1295 }; | 1295 }; |
| 1296 EXPECT_VERIFIES(data); | 1296 EXPECT_VERIFIES(data); |
| 1297 } | 1297 } |
| 1298 | 1298 |
| 1299 } // namespace wasm | 1299 } // namespace wasm |
| 1300 } // namespace internal | 1300 } // namespace internal |
| 1301 } // namespace v8 | 1301 } // namespace v8 |
| OLD | NEW |