Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -507,7 +507,7 @@ Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) { StartFunction = readVaruint32(Ptr); - if (StartFunction < FunctionTypes.size()) + if (StartFunction >= FunctionTypes.size()) return make_error("Invalid start function", object_error::parse_failed); return Error::success(); Index: llvm/trunk/test/Object/wasm-invalid-start.test =================================================================== --- llvm/trunk/test/Object/wasm-invalid-start.test +++ llvm/trunk/test/Object/wasm-invalid-start.test @@ -0,0 +1,10 @@ +# RUN: yaml2obj %s | not llvm-objdump -h - 2>&1 | FileCheck %s + +!WASM +FileHeader: + Version: 0x00000001 +Sections: + - Type: START + StartFunction: 0 + +# CHECK: {{.*}}: Invalid start function Index: llvm/trunk/test/ObjectYAML/wasm/function_section.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/wasm/function_section.yaml +++ llvm/trunk/test/ObjectYAML/wasm/function_section.yaml @@ -4,9 +4,7 @@ Version: 0x00000001 Sections: - Type: FUNCTION - FunctionTypes: - - 1 - - 0 + FunctionTypes: [ 1, 0 ] ... # CHECK: --- !WASM # CHECK: FileHeader: Index: llvm/trunk/test/ObjectYAML/wasm/start_section.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/wasm/start_section.yaml +++ llvm/trunk/test/ObjectYAML/wasm/start_section.yaml @@ -1,8 +1,17 @@ # RUN: yaml2obj %s | obj2yaml | FileCheck %s + --- !WASM FileHeader: Version: 0x00000001 Sections: + - Type: TYPE + Signatures: + - ReturnType: I32 + ParamTypes: + - F32 + - F32 + - Type: FUNCTION + FunctionTypes: [ 0, 0, 0 ] - Type: START StartFunction: 1 ...