Fix crash in PDB when loading corrupt file.
authorZachary Turner <zturner@google.com>
Fri, 29 Apr 2016 18:09:19 +0000 (18:09 +0000)
committerZachary Turner <zturner@google.com>
Fri, 29 Apr 2016 18:09:19 +0000 (18:09 +0000)
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

index 6e5f536..f9ce344 100644 (file)
@@ -123,6 +123,13 @@ std::error_code PDBFile::parseFileHeaders() {
   Context->SB =
       reinterpret_cast<const SuperBlock *>(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))