Bug 1246957: Make the data section require the memory section; r=luke
authorBenjamin Bouvier <benj@benj.me>
Tue, 09 Feb 2016 17:13:30 +0100
changeset 330094 2b116adb01738259a94b6488d7b0d06c1a63729a
parent 330087 f1f70fa6338e63a600046c30dafee0eb3cff51ad
child 330095 5c4a80fca486941332b5befda970c281e887cb2a
push id10675
push userbmo:james@hoppipolla.co.uk
push dateWed, 10 Feb 2016 15:13:04 +0000
reviewersluke
bugs1246957
milestone47.0a1
Bug 1246957: Make the data section require the memory section; r=luke
js/src/asmjs/Wasm.cpp
js/src/jit-test/tests/wasm/binary.js
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -947,16 +947,19 @@ DecodeCodeSection(JSContext* cx, Decoder
 }
 
 static bool
 DecodeDataSection(JSContext* cx, Decoder& d, Handle<ArrayBufferObject*> heap)
 {
     if (!d.readCStringIf(DataSection))
         return true;
 
+    if (!heap)
+        return Fail(cx, d, "data section requires a memory section");
+
     uint32_t sectionStart;
     if (!d.startSection(&sectionStart))
         return Fail(cx, d, "expected data section byte size");
 
     uint32_t numSegments;
     if (!d.readVarU32(&numSegments))
         return Fail(cx, d, "expected number of data segments");
 
--- a/js/src/jit-test/tests/wasm/binary.js
+++ b/js/src/jit-test/tests/wasm/binary.js
@@ -13,16 +13,17 @@ const ver2 = 0xff;
 const ver3 = 0xff;
 
 // Section names
 const sigSectionStr = "sig";
 const declSectionStr = "decl";
 const importSectionStr = "import";
 const exportSectionStr = "export";
 const codeSectionStr = "code";
+const dataSectionStr = "data";
 const funcSubsectionStr = "func";
 
 const magicError = /failed to match magic number/;
 const versionError = /failed to match binary version/;
 const extraError = /failed to consume all bytes of module/;
 const sectionError = /failed to read section name/;
 
 const I32Code = 0;
@@ -165,8 +166,10 @@ assertErrorMessage(() => wasmEval(toBuf(
 wasmEval(toBuf(moduleWithSections([trivialSigSection, importSection([])])));
 wasmEval(toBuf(moduleWithSections([trivialSigSection, importSection([{sigIndex:0, module:"a", func:""}])])), {a:()=>{}});
 
 wasmEval(toBuf(moduleWithSections([
     trivialSigSection,
     importSection([{sigIndex:0, module:"a", func:""}]),
     trivialDeclSection,
     trivialCodeSection])), {a:()=>{}});
+
+assertErrorMessage(() => wasmEval(toBuf(moduleWithSections([ {name: dataSectionStr, body: [], } ]))), Error, /data section requires a memory section/);