Index: llvm/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/lib/Object/WasmObjectFile.cpp +++ llvm/lib/Object/WasmObjectFile.cpp @@ -218,7 +218,12 @@ if (Section.Type == wasm::WASM_SEC_CUSTOM) { const uint8_t *NameStart = Ctx.Ptr; Section.Name = readString(Ctx); - Size -= Ctx.Ptr - NameStart; + const uint32_t NameLength = Ctx.Ptr - NameStart; + if (NameLength > Size) + return make_error( + "Custom section name extends beyond section", + object_error::parse_failed); + Size -= NameLength; } Section.Content = ArrayRef(Ctx.Ptr, Size); Ctx.Ptr += Size; Index: llvm/test/Object/wasm-string-outside-section.test =================================================================== --- /dev/null +++ llvm/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: Custom section name extends beyond section