Chromium Code Reviews

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2483053005: [wasm] Check data segments for zero-sized memory. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« src/wasm/wasm-module.cc ('K') | « src/wasm/wasm-module.cc ('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 <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 792 matching lines...)
803 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, 803 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
804 data + arraysize(data), 804 data + arraysize(data),
805 ModuleOrigin::kWasmOrigin); 805 ModuleOrigin::kWasmOrigin);
806 if (thrower.error()) { 806 if (thrower.error()) {
807 thrower.Reify()->Print(); 807 thrower.Reify()->Print();
808 CHECK(false); 808 CHECK(false);
809 } 809 }
810 } 810 }
811 Cleanup(); 811 Cleanup();
812 } 812 }
813
814 TEST(EmptyMemoryNonEmptyDataSegment) {
815 {
816 Isolate* isolate = CcTest::InitIsolateOnce();
817 HandleScope scope(isolate);
818 testing::SetupIsolateForWasmModule(isolate);
819
820 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit");
821
822 const byte data[] = {
823 WASM_MODULE_HEADER, // --
824 kMemorySectionCode, // --
825 U32V_1(4), // section size
826 ENTRY_COUNT(1), // --
827 kResizableMaximumFlag, // --
828 0, // initial size
829 0, // maximum size
830 kDataSectionCode, // --
831 U32V_1(7), // section size
832 ENTRY_COUNT(1), // --
833 0, // linear memory index
834 WASM_I32V_1(8), // destination offset
835 kExprEnd,
836 U32V_1(1), // source size
837 'c' // data bytes
838 };
839
840 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
841 data + arraysize(data),
842 ModuleOrigin::kWasmOrigin);
843 // It should not be possible to instantiate this module.
844 CHECK(thrower.error());
845 }
846 Cleanup();
847 }
848
849 TEST(EmptyMemoryEmptyDataSegment) {
850 {
851 Isolate* isolate = CcTest::InitIsolateOnce();
852 HandleScope scope(isolate);
853 testing::SetupIsolateForWasmModule(isolate);
854
855 ErrorThrower thrower(isolate, "Run_WasmModule_InitDataAtTheUpperLimit");
856
857 const byte data[] = {
858 WASM_MODULE_HEADER, // --
859 kMemorySectionCode, // --
860 U32V_1(4), // section size
861 ENTRY_COUNT(1), // --
862 kResizableMaximumFlag, // --
863 0, // initial size
864 0, // maximum size
865 kDataSectionCode, // --
866 U32V_1(6), // section size
867 ENTRY_COUNT(1), // --
868 0, // linear memory index
869 WASM_I32V_1(24), // destination offset
870 kExprEnd,
871 U32V_1(0), // source size
872 };
873
874 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
875 data + arraysize(data),
876 ModuleOrigin::kWasmOrigin);
877 // It should be possible to instantiate this module.
878 CHECK(!thrower.error());
879 }
880 Cleanup();
881 }
OLDNEW
« src/wasm/wasm-module.cc ('K') | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine