[llvm] r268316 - [llvm-pdbdump] Fix read past EOF when file is too small.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 15:16:58 PDT 2016


Author: zturner
Date: Mon May  2 17:16:57 2016
New Revision: 268316

URL: http://llvm.org/viewvc/llvm-project?rev=268316&view=rev
Log:
[llvm-pdbdump] Fix read past EOF when file is too small.

Modified:
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=268316&r1=268315&r2=268316&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Mon May  2 17:16:57 2016
@@ -119,6 +119,8 @@ StringRef PDBFile::getBlockData(uint32_t
 std::error_code PDBFile::parseFileHeaders() {
   std::error_code EC;
   MemoryBufferRef BufferRef = *Context->Buffer;
+  if (BufferRef.getBufferSize() < sizeof(SuperBlock))
+    return std::make_error_code(std::errc::illegal_byte_sequence);
 
   Context->SB =
       reinterpret_cast<const SuperBlock *>(BufferRef.getBufferStart());
@@ -130,6 +132,8 @@ std::error_code PDBFile::parseFileHeader
     // An invalid block size suggests a corrupt PDB file.
     return std::make_error_code(std::errc::illegal_byte_sequence);
   }
+  if (BufferRef.getBufferSize() % SB->BlockSize != 0)
+    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))




More information about the llvm-commits mailing list