diff options
| -rw-r--r-- | llvm/include/llvm/Object/ELF.h | 9 | ||||
| -rw-r--r-- | llvm/test/Object/invalid.test | 2 |
2 files changed, 4 insertions, 7 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h index fceb0a19f80..c06fa75231b 100644 --- a/llvm/include/llvm/Object/ELF.h +++ b/llvm/include/llvm/Object/ELF.h @@ -118,8 +118,6 @@ public: Elf_Sym_Range symbols(const Elf_Shdr *Sec) const { if (!Sec) return makeArrayRef<Elf_Sym>(nullptr, nullptr); - if (Sec->sh_entsize != sizeof(Elf_Sym)) - report_fatal_error("Invalid symbol size"); auto V = getSectionContentsAsArray<Elf_Sym>(Sec); if (!V) report_fatal_error(V.getError().message()); @@ -127,8 +125,6 @@ public: } Elf_Rela_Range relas(const Elf_Shdr *Sec) const { - if (Sec->sh_entsize != sizeof(Elf_Rela)) - report_fatal_error("Invalid relocation entry size"); auto V = getSectionContentsAsArray<Elf_Rela>(Sec); if (!V) report_fatal_error(V.getError().message()); @@ -136,8 +132,6 @@ public: } Elf_Rel_Range rels(const Elf_Shdr *Sec) const { - if (Sec->sh_entsize != sizeof(Elf_Rel)) - report_fatal_error("Invalid relocation entry size"); auto V = getSectionContentsAsArray<Elf_Rel>(Sec); if (!V) report_fatal_error(V.getError().message()); @@ -224,6 +218,9 @@ template <class ELFT> template <typename T> ErrorOr<ArrayRef<T>> ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const { + if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1) + return object_error::parse_failed; + uintX_t Offset = Sec->sh_offset; uintX_t Size = Sec->sh_size; diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test index 774aa4776b5..9f5587422d1 100644 --- a/llvm/test/Object/invalid.test +++ b/llvm/test/Object/invalid.test @@ -35,7 +35,7 @@ SECTION-NEXT: AddressAlignment: SECTION-NEXT: EntrySize: 32 RUN: not llvm-readobj -t %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-SYM-SIZE %s -INVALID-SYM-SIZE: Invalid symbol size +INVALID-SYM-SIZE: Invalid data was encountered while parsing the file RUN: not llvm-readobj --dyn-symbols %p/Inputs/invalid-sh_entsize.elf 2>&1 | FileCheck --check-prefix=INVALID-DYNSYM-SIZE %s INVALID-DYNSYM-SIZE: Invalid entity size |

