Index: llvm/trunk/include/llvm/Object/ELF.h =================================================================== --- llvm/trunk/include/llvm/Object/ELF.h +++ llvm/trunk/include/llvm/Object/ELF.h @@ -319,8 +319,12 @@ Header = reinterpret_cast(base()); - if (Header->e_shoff == 0) + if (Header->e_shoff == 0) { + if (Header->e_shnum != 0) + report_fatal_error( + "e_shnum should be zero if a file has no section header table"); return; + } const uint64_t SectionTableOffset = Header->e_shoff; Index: llvm/trunk/test/Object/invalid.test =================================================================== --- llvm/trunk/test/Object/invalid.test +++ llvm/trunk/test/Object/invalid.test @@ -55,6 +55,9 @@ RUN: not llvm-readobj -t %p/Inputs/invalid-xindex-size.elf 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file. +RUN: not llvm-readobj -t %p/Inputs/invalid-e_shnum.elf 2>&1 | FileCheck --check-prefix=INVALID-SH-NUM %s +INVALID-SH-NUM: e_shnum should be zero if a file has no section header table + RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \ RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s INVALID-EXT-SYMTAB-INDEX: Invalid symbol table index