From 9213ba530432bd57b647aa90ea65a735a6d40334 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 29 Apr 2016 18:09:19 +0000 Subject: 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 --- llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'llvm/lib/DebugInfo') diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index 6e5f536cc70..f9ce3445bb8 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)) -- cgit v1.2.3