Skip to content

Commit daaffbe

Browse files
committed
Give a better error message if the file lacks a section header table
Currently, patchelf outputs this when run on a UPX-compressed ELF file: patchelf: patchelf.cc:420: ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym, Elf_Verneed>::ElfFile(FileContents): Assertion `shstrtabIndex < shdrs.size()' failed. Make it give a nicer error message: patchelf: no section headers. The input file is probably a statically linked, self-decompressing binary Fixes #63
1 parent bfc3db3 commit daaffbe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/patchelf.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,13 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fileContents)
392392
error("wrong ELF type");
393393

394394
if ((size_t) (rdi(hdr->e_phoff) + rdi(hdr->e_phnum) * rdi(hdr->e_phentsize)) > fileContents->size())
395-
error("missing program headers");
395+
error("program header table out of bounds");
396+
397+
if (rdi(hdr->e_shnum) == 0)
398+
error("no section headers. The input file is probably a statically linked, self-decompressing binary");
396399

397400
if ((size_t) (rdi(hdr->e_shoff) + rdi(hdr->e_shnum) * rdi(hdr->e_shentsize)) > fileContents->size())
398-
error("missing section headers");
401+
error("section header table out of bounds");
399402

400403
if (rdi(hdr->e_phentsize) != sizeof(Elf_Phdr))
401404
error("program headers have wrong size");

0 commit comments

Comments
 (0)