diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index 1ffdc01bcd3..c7df30a5903 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -39,14 +39,15 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) { R.reset(new ELFObjectFile>(Obj, EC)); else return object_error::parse_failed; - } else { - assert(Ident.first == ELF::ELFCLASS64); + } else if (Ident.first == ELF::ELFCLASS64) { if (Ident.second == ELF::ELFDATA2LSB) R.reset(new ELFObjectFile>(Obj, EC)); else if (Ident.second == ELF::ELFDATA2MSB) R.reset(new ELFObjectFile>(Obj, EC)); else return object_error::parse_failed; + } else { + return object_error::parse_failed; } if (EC) diff --git a/test/DebugInfo/Inputs/invalid.elf.3 b/test/DebugInfo/Inputs/invalid.elf.3 new file mode 100644 index 00000000000..f4944600004 --- /dev/null +++ b/test/DebugInfo/Inputs/invalid.elf.3 @@ -0,0 +1 @@ +ELF‚Lþ'ELFB \ No newline at end of file diff --git a/test/DebugInfo/dwarfdump-invalid.test b/test/DebugInfo/dwarfdump-invalid.test index 5b616bd5581..da5b23e30ce 100644 --- a/test/DebugInfo/dwarfdump-invalid.test +++ b/test/DebugInfo/dwarfdump-invalid.test @@ -2,4 +2,5 @@ RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF +RUN: llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF INVALID-ELF: Invalid data was encountered while parsing the file