diff --git a/js/src/asmjs/Wasm.cpp b/js/src/asmjs/Wasm.cpp index 0dd640414ac5..b43c315188b9 100644 --- a/js/src/asmjs/Wasm.cpp +++ b/js/src/asmjs/Wasm.cpp @@ -312,7 +312,7 @@ DecodeDeclarationSection(JSContext* cx, Decoder& d, ModuleGeneratorData* init) if (!d.readVarU32(&sigIndex)) return Fail(cx, d, "expected declaration signature index"); - if (sigIndex > init->sigs.length()) + if (sigIndex >= init->sigs.length()) return Fail(cx, d, "declaration signature index out of range"); init->funcSigs[i] = &init->sigs[sigIndex]; diff --git a/js/src/jit-test/tests/wasm/binary.js b/js/src/jit-test/tests/wasm/binary.js index b55912e1b01c..999ee0a237fb 100644 --- a/js/src/jit-test/tests/wasm/binary.js +++ b/js/src/jit-test/tests/wasm/binary.js @@ -108,3 +108,15 @@ wasmEval(toBuf(moduleWithSections([sigSection([{args:[I32Code], ret:VoidCode}])] assertErrorMessage(() => wasmEval(toBuf(moduleWithSections([sigSection([{args:[], ret:100}])]))), Error, /bad expression type/); assertErrorMessage(() => wasmEval(toBuf(moduleWithSections([sigSection([{args:[100], ret:VoidCode}])]))), Error, /bad value type/); + +function declSection(decls) { + var body = []; + body.push(...varU32(decls.length)); + for (var decl of decls) + body.push(...varU32(decl)); + return { name: declSectionStr, body }; +} + +assertThrowsInstanceOf(() => wasmEval(toBuf(moduleWithSections([sigSection([]), declSection([0])]))), Error, /signature index out of range/); +assertThrowsInstanceOf(() => wasmEval(toBuf(moduleWithSections([sigSection([{args:[], ret:VoidCode}]), declSection([1])]))), Error, /signature index out of range/); +wasmEval(toBuf(moduleWithSections([sigSection([{args:[], ret:VoidCode}]), declSection([0])])));