From: Zachary Turner Date: Fri, 29 Apr 2016 18:09:19 +0000 (+0000) Subject: Fix crash in PDB when loading corrupt file. X-Git-Tag: llvmorg-3.9.0-rc1~7427 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9213ba530432bd57b647aa90ea65a735a6d40334;p=platform%2Fupstream%2Fllvm.git Fix crash in PDB when loading corrupt file. There are probably hundreds of crashers we can find by fuzzing more. For now we do the simplest possible validation of the block size. Later, more complicated validations can verify that other fields of the super block such as directory size, number of blocks, agree with the size of the file etc. llvm-svn: 268084 --- diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index 6e5f536..f9ce344 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -123,6 +123,13 @@ std::error_code PDBFile::parseFileHeaders() { Context->SB = reinterpret_cast(BufferRef.getBufferStart()); const SuperBlock *SB = Context->SB; + switch (SB->BlockSize) { + case 512: case 1024: case 2048: case 4096: + break; + default: + // An invalid block size suggests a corrupt PDB file. + return std::make_error_code(std::errc::illegal_byte_sequence); + } // Make sure the file is sufficiently large to hold a super block. if (BufferRef.getBufferSize() < sizeof(SuperBlock))