Index: llvm/trunk/include/llvm/Object/ELF.h =================================================================== --- llvm/trunk/include/llvm/Object/ELF.h +++ llvm/trunk/include/llvm/Object/ELF.h @@ -225,7 +225,8 @@ ArrayRef ShndxTable) const { assert(Sym->st_shndx == ELF::SHN_XINDEX); unsigned Index = Sym - FirstSym; - + if (Index >= ShndxTable.size()) + report_fatal_error("Invalid symbol table index"); // The size of the table was checked in getSHNDXTable. return ShndxTable[Index]; } Index: llvm/trunk/test/Object/invalid.test =================================================================== --- llvm/trunk/test/Object/invalid.test +++ llvm/trunk/test/Object/invalid.test @@ -54,3 +54,7 @@ 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-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