Index: include/llvm/Object/ELF.h =================================================================== --- include/llvm/Object/ELF.h +++ include/llvm/Object/ELF.h @@ -367,7 +367,10 @@ if (Header->e_shentsize != sizeof(Elf_Shdr)) report_fatal_error( "Invalid section header entry size (e_shentsize) in ELF header"); - return reinterpret_cast(base() + Header->e_shoff); + const uint8_t *Addr = base() + Header->e_shoff; + if ((uintptr_t)(Addr) & (AlignOf::Alignment - 1)) + report_fatal_error("Invalid address alignment of section headers"); + return reinterpret_cast(Addr); } template 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