Index: include/llvm/Object/ELF.h =================================================================== --- include/llvm/Object/ELF.h +++ include/llvm/Object/ELF.h @@ -367,6 +367,8 @@ if (Header->e_shentsize != sizeof(Elf_Shdr)) report_fatal_error( "Invalid section header entry size (e_shentsize) in ELF header"); + if (Header->e_shoff & (AlignOf::Alignment - 1)) + report_fatal_error("Invalid address alignment of section headers"); return reinterpret_cast(base() + Header->e_shoff); } Index: test/Object/invalid.test =================================================================== --- test/Object/invalid.test +++ test/Object/invalid.test @@ -64,3 +64,7 @@ RUN: not llvm-readobj -r %p/Inputs/invalid-relocation-sec-sh_offset.elf-x86-64 2>&1 | \ RUN: FileCheck --check-prefix=INVALID-RELOC-SH-OFFSET %s INVALID-RELOC-SH-OFFSET: Invalid data was encountered while parsing the file + +RUN: not llvm-readobj -t %p/Inputs/invalid-sections-address-alignment.x86-64 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-SEC-ADDRESS-ALIGNMENT %s +INVALID-SEC-ADDRESS-ALIGNMENT: Invalid address alignment of section headers