diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index 716b3b93c0ea..c968295b8400 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -602,7 +602,7 @@ void ELFFile::VerifyStrTab(const Elf_Shdr *sh) const { template uint64_t ELFFile::getNumSections() const { assert(Header && "Header not initialized!"); - if (Header->e_shnum == ELF::SHN_UNDEF) { + if (Header->e_shnum == ELF::SHN_UNDEF && Header->e_shoff > 0) { assert(SectionHeaderTable && "SectionHeaderTable not initialized!"); return SectionHeaderTable->sh_size; }