[BinaryFormat] Fix out of bounds read.

Found by OSS-FUZZ!
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3220

llvm-svn: 312238
This commit is contained in:
Benjamin Kramer
2017-08-31 12:50:42 +00:00
parent bfcac0b480
commit 80df642395
2 changed files with 5 additions and 2 deletions

View File

@@ -182,7 +182,7 @@ file_magic llvm::identify_magic(StringRef Magic) {
break;
case 'M': // Possible MS-DOS stub on Windows PE file
if (startswith(Magic, "MZ")) {
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() &&