From d6192f482ffa7c3162b60aa0c68b5ea38e350a11 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 2 May 2016 22:16:57 +0000 Subject: [PATCH] [llvm-pdbdump] Fix read past EOF when file is too small. llvm-svn: 268316 --- llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index f9ce344..df47ced 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -119,6 +119,8 @@ StringRef PDBFile::getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const { 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(BufferRef.getBufferStart()); @@ -130,6 +132,8 @@ std::error_code PDBFile::parseFileHeaders() { // 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)) -- 2.7.4