| 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 609 |
| 610 if (result.val) delete result.val; | 610 if (result.val) delete result.val; |
| 611 } | 611 } |
| 612 | 612 |
| 613 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data)); | 613 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data)); |
| 614 } | 614 } |
| 615 | 615 |
| 616 | 616 |
| 617 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidSource) { | 617 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidSource) { |
| 618 const int dest_addr = 0x100; | 618 const int dest_addr = 0x100; |
| 619 const byte mem_size_log2 = 15; | 619 const byte mem_pages = 1; |
| 620 const int kHeaderSize = 8; | 620 const int kHeaderSize = 8; |
| 621 const int kDataSize = 19; | 621 const int kDataSize = 19; |
| 622 const int kTotalSize = kHeaderSize + kDataSize; | 622 const int kTotalSize = kHeaderSize + kDataSize; |
| 623 | 623 |
| 624 for (int source_offset = 0; source_offset < 5 + kDataSize; source_offset++) { | 624 for (int source_offset = 0; source_offset < 5 + kDataSize; source_offset++) { |
| 625 for (int source_size = -1; source_size < 5 + kDataSize; source_size += 3) { | 625 for (int source_size = -1; source_size < 5 + kDataSize; source_size += 3) { |
| 626 byte data[] = { | 626 byte data[] = { |
| 627 kDeclMemory, | 627 kDeclMemory, |
| 628 mem_size_log2, | 628 mem_pages, |
| 629 mem_size_log2, | 629 mem_pages, |
| 630 1, | 630 1, |
| 631 kDeclDataSegments, | 631 kDeclDataSegments, |
| 632 1, | 632 1, |
| 633 U32_LE(dest_addr), | 633 U32_LE(dest_addr), |
| 634 U32_LE(source_offset), | 634 U32_LE(source_offset), |
| 635 U32_LE(source_size), | 635 U32_LE(source_size), |
| 636 1, // init | 636 1, // init |
| 637 }; | 637 }; |
| 638 | 638 |
| 639 STATIC_ASSERT(kDataSize == arraysize(data)); | 639 STATIC_ASSERT(kDataSize == arraysize(data)); |
| 640 | 640 |
| 641 if (source_offset < kTotalSize && source_size >= 0 && | 641 if (source_offset < kTotalSize && source_size >= 0 && |
| 642 (source_offset + source_size) <= kTotalSize) { | 642 (source_offset + source_size) <= kTotalSize) { |
| 643 EXPECT_VERIFIES(data); | 643 EXPECT_VERIFIES(data); |
| 644 } else { | 644 } else { |
| 645 EXPECT_FAILURE(data); | 645 EXPECT_FAILURE(data); |
| 646 } | 646 } |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 | 651 |
| 652 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) { | 652 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) { |
| 653 const int source_size = 3; | 653 const int source_size = 3; |
| 654 const int source_offset = 11; | 654 const int source_offset = 11; |
| 655 | 655 |
| 656 for (byte mem_size_log2 = 12; mem_size_log2 < 20; mem_size_log2++) { | 656 for (byte mem_pages = 1; mem_pages < 16; mem_pages++) { |
| 657 int mem_size = 1 << mem_size_log2; | 657 int mem_size = mem_pages * 0x10000; // 64k pages. |
| 658 | 658 |
| 659 for (int dest_addr = mem_size - source_size; | 659 for (int dest_addr = mem_size - source_size; |
| 660 dest_addr < mem_size + source_size; dest_addr++) { | 660 dest_addr < mem_size + source_size; dest_addr++) { |
| 661 byte data[] = { | 661 byte data[] = { |
| 662 kDeclMemory, | 662 kDeclMemory, |
| 663 mem_size_log2, | 663 mem_pages, |
| 664 mem_size_log2, | 664 mem_pages, |
| 665 1, | 665 1, |
| 666 kDeclDataSegments, | 666 kDeclDataSegments, |
| 667 1, | 667 1, |
| 668 U32_LE(dest_addr), | 668 U32_LE(dest_addr), |
| 669 U32_LE(source_offset), | 669 U32_LE(source_offset), |
| 670 U32_LE(source_size), | 670 U32_LE(source_size), |
| 671 1, // init | 671 1, // init |
| 672 }; | 672 }; |
| 673 | 673 |
| 674 if (dest_addr <= (mem_size - source_size)) { | 674 if (dest_addr <= (mem_size - source_size)) { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 for (int length = 13; length < sizeof(data); length++) { | 1147 for (int length = 13; length < sizeof(data); length++) { |
| 1148 ModuleResult result = DecodeModule(data, data + length); | 1148 ModuleResult result = DecodeModule(data, data + length); |
| 1149 EXPECT_FALSE(result.ok()); | 1149 EXPECT_FALSE(result.ok()); |
| 1150 if (result.val) delete result.val; | 1150 if (result.val) delete result.val; |
| 1151 } | 1151 } |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 } // namespace wasm | 1154 } // namespace wasm |
| 1155 } // namespace internal | 1155 } // namespace internal |
| 1156 } // namespace v8 | 1156 } // namespace v8 |
| OLD | NEW |