summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-10 05:32:05 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-10 05:32:05 +0000
commit1b79e9a5b916c7c3684e82a1cec29bd6ac91bd3e (patch)
tree66313fadcbf9e655c6678193e89348d2735677fd
parent6211b1f1f9c1434d9612aada7337ca9c6bca4a10 (diff)
downloadbcm5719-llvm-1b79e9a5b916c7c3684e82a1cec29bd6ac91bd3e.tar.gz
bcm5719-llvm-1b79e9a5b916c7c3684e82a1cec29bd6ac91bd3e.zip
[pdb] Sanity check the stream map
Some abstractions in LLVM "know" that they are reading in-bounds, FixedStreamArray, and provide a simple result. This breaks down if the stream map is bogus. llvm-svn: 275010
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Raw/PDBFile.h2
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp8
2 files changed, 8 insertions, 2 deletions
diff --git a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFile.h b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
index a8e1dc5c307..11ddb2e63eb 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
@@ -82,7 +82,7 @@ public:
uint32_t getStreamByteSize(uint32_t StreamIndex) const override;
ArrayRef<support::ulittle32_t>
getStreamBlockList(uint32_t StreamIndex) const override;
- size_t getFileSize() const;
+ uint32_t getFileSize() const;
Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex,
uint32_t NumBytes) const override;
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
index b289fd0124b..ce2446cba80 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
@@ -71,7 +71,7 @@ PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
return StreamMap[StreamIndex];
}
-size_t PDBFile::getFileSize() const { return Buffer->getLength(); }
+uint32_t PDBFile::getFileSize() const { return Buffer->getLength(); }
Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex,
uint32_t NumBytes) const {
@@ -154,6 +154,12 @@ Error PDBFile::parseStreamData() {
ArrayRef<support::ulittle32_t> Blocks;
if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks))
return EC;
+ for (uint32_t Block : Blocks) {
+ uint64_t BlockEndOffset = (uint64_t)(Block + 1) * SB->BlockSize;
+ if (BlockEndOffset > getFileSize())
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Stream block map is corrupt.");
+ }
StreamMap.push_back(Blocks);
}
OpenPOWER on IntegriCloud