Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -216,9 +216,16 @@ return make_error("Section too large", object_error::parse_failed); if (Section.Type == wasm::WASM_SEC_CUSTOM) { - const uint8_t *NameStart = Ctx.Ptr; - Section.Name = readString(Ctx); - Size -= Ctx.Ptr - NameStart; + WasmObjectFile::ReadContext SectionCtx; + SectionCtx.Start = Ctx.Ptr; + SectionCtx.Ptr = Ctx.Ptr; + SectionCtx.End = Ctx.Ptr + Size; + + Section.Name = readString(SectionCtx); + + uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start; + Ctx.Ptr += SectionNameSize; + Size -= SectionNameSize; } Section.Content = ArrayRef(Ctx.Ptr, Size); Ctx.Ptr += Size; Index: llvm/trunk/test/Object/wasm-string-outside-section.test =================================================================== --- llvm/trunk/test/Object/wasm-string-outside-section.test +++ llvm/trunk/test/Object/wasm-string-outside-section.test @@ -0,0 +1,3 @@ +RUN: not llvm-objdump -s %p/Inputs/WASM/string-outside-section.wasm 2>&1 | FileCheck %s + +CHECK: LLVM ERROR: EOF while reading string