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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/snapshot/code-serializer.h" | 8 #include "src/snapshot/code-serializer.h" |
9 #include "src/version.h" | 9 #include "src/version.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, | 804 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
805 data + arraysize(data), | 805 data + arraysize(data), |
806 ModuleOrigin::kWasmOrigin); | 806 ModuleOrigin::kWasmOrigin); |
807 if (thrower.error()) { | 807 if (thrower.error()) { |
808 thrower.Reify()->Print(); | 808 thrower.Reify()->Print(); |
809 CHECK(false); | 809 CHECK(false); |
810 } | 810 } |
811 } | 811 } |
812 Cleanup(); | 812 Cleanup(); |
813 } | 813 } |
| 814 |
| 815 TEST(EmptyMemoryNonEmptyDataSegment) { |
| 816 { |
| 817 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 818 HandleScope scope(isolate); |
| 819 testing::SetupIsolateForWasmModule(isolate); |
| 820 |
| 821 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit"); |
| 822 |
| 823 const byte data[] = { |
| 824 WASM_MODULE_HEADER, // -- |
| 825 kMemorySectionCode, // -- |
| 826 U32V_1(4), // section size |
| 827 ENTRY_COUNT(1), // -- |
| 828 kResizableMaximumFlag, // -- |
| 829 0, // initial size |
| 830 0, // maximum size |
| 831 kDataSectionCode, // -- |
| 832 U32V_1(7), // section size |
| 833 ENTRY_COUNT(1), // -- |
| 834 0, // linear memory index |
| 835 WASM_I32V_1(8), // destination offset |
| 836 kExprEnd, |
| 837 U32V_1(1), // source size |
| 838 'c' // data bytes |
| 839 }; |
| 840 |
| 841 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
| 842 data + arraysize(data), |
| 843 ModuleOrigin::kWasmOrigin); |
| 844 // It should not be possible to instantiate this module. |
| 845 CHECK(thrower.error()); |
| 846 } |
| 847 Cleanup(); |
| 848 } |
| 849 |
| 850 TEST(EmptyMemoryEmptyDataSegment) { |
| 851 { |
| 852 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 853 HandleScope scope(isolate); |
| 854 testing::SetupIsolateForWasmModule(isolate); |
| 855 |
| 856 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit"); |
| 857 |
| 858 const byte data[] = { |
| 859 WASM_MODULE_HEADER, // -- |
| 860 kMemorySectionCode, // -- |
| 861 U32V_1(4), // section size |
| 862 ENTRY_COUNT(1), // -- |
| 863 kResizableMaximumFlag, // -- |
| 864 0, // initial size |
| 865 0, // maximum size |
| 866 kDataSectionCode, // -- |
| 867 U32V_1(6), // section size |
| 868 ENTRY_COUNT(1), // -- |
| 869 0, // linear memory index |
| 870 WASM_I32V_1(24), // destination offset |
| 871 kExprEnd, |
| 872 U32V_1(0), // source size |
| 873 }; |
| 874 |
| 875 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
| 876 data + arraysize(data), |
| 877 ModuleOrigin::kWasmOrigin); |
| 878 // It should be possible to instantiate this module. |
| 879 CHECK(!thrower.error()); |
| 880 } |
| 881 Cleanup(); |
| 882 } |
| 883 |
| 884 TEST(MemoryWithOOBEmptyDataSegment) { |
| 885 { |
| 886 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 887 HandleScope scope(isolate); |
| 888 testing::SetupIsolateForWasmModule(isolate); |
| 889 |
| 890 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit"); |
| 891 |
| 892 const byte data[] = { |
| 893 WASM_MODULE_HEADER, // -- |
| 894 kMemorySectionCode, // -- |
| 895 U32V_1(4), // section size |
| 896 ENTRY_COUNT(1), // -- |
| 897 kResizableMaximumFlag, // -- |
| 898 1, // initial size |
| 899 1, // maximum size |
| 900 kDataSectionCode, // -- |
| 901 U32V_1(9), // section size |
| 902 ENTRY_COUNT(1), // -- |
| 903 0, // linear memory index |
| 904 WASM_I32V_4(0x2468ace), // destination offset |
| 905 kExprEnd, |
| 906 U32V_1(0), // source size |
| 907 }; |
| 908 |
| 909 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
| 910 data + arraysize(data), |
| 911 ModuleOrigin::kWasmOrigin); |
| 912 // It should be possible to instantiate this module. |
| 913 CHECK(!thrower.error()); |
| 914 } |
| 915 Cleanup(); |
| 916 } |
OLD | NEW |