1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Fix buffer overflow.

We were reading past the end of the buffer.

llvm-svn: 316143
This commit is contained in:
Rafael Espindola 2017-10-19 01:25:48 +00:00
parent 73a2505e62
commit 4d7e642f7d
3 changed files with 4 additions and 1 deletions

View File

@ -185,7 +185,7 @@ file_magic llvm::identify_magic(StringRef Magic) {
if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) {
uint32_t off = read32le(Magic.data() + 0x3c);
// PE/COFF file, either EXE or DLL.
if (off < Magic.size() &&
if (off + sizeof(COFF::PEMagic) <= Magic.size() &&
memcmp(Magic.data() + off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0)
return file_magic::pecoff_executable;
}

Binary file not shown.

View File

@ -86,3 +86,6 @@ INVALID-REL-SYM: invalid section offset
RUN: not llvm-readobj -r %p/Inputs/invalid-buffer.elf 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s
INVALID-BUFFER: Invalid buffer
RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
COFF-HEADER: The file was not recognized as a valid object file