summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
index dbdb1c52d5f..9a2b142ccfb 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
@@ -53,7 +53,7 @@ struct PublicsStream::HeaderInfo {
ulittle16_t ISectThunkTable;
char Padding[2];
ulittle32_t OffThunkTable;
- ulittle32_t NumSects;
+ ulittle32_t NumSections;
};
@@ -74,6 +74,15 @@ struct PublicsStream::HRFile {
ulittle32_t CRef;
};
+// This struct is defined as "SO" in langapi/include/pdb.h.
+namespace {
+struct SectionOffset {
+ ulittle32_t Off;
+ ulittle16_t Isect;
+ char Padding[2];
+};
+}
+
PublicsStream::PublicsStream(PDBFile &File, uint32_t StreamNum)
: StreamNum(StreamNum), Stream(StreamNum, File) {}
@@ -123,10 +132,37 @@ Error PublicsStream::reload() {
for (uint8_t B : Bitmap)
NumBuckets += countPopulation(B);
- // Buckets follow.
- if (Reader.bytesRemaining() < NumBuckets * sizeof(uint32_t))
+ // We don't yet understand the following data structures completely,
+ // but we at least know the types and sizes. Here we are trying
+ // to read the stream till end so that we at least can detect
+ // corrupted streams.
+
+ // Hash buckets follow.
+ HashBuckets.resize(NumBuckets);
+ if (auto EC = Reader.readArray<uint32_t>(HashBuckets))
return make_error<RawError>(raw_error_code::corrupt_file,
"Hash buckets corrupted.");
+ // Something called "address map" follows.
+ AddressMap.resize(Header->AddrMap / sizeof(uint32_t));
+ if (auto EC = Reader.readArray<uint32_t>(AddressMap))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Could not read an address map.");
+
+ // Something called "thunk map" follows.
+ ThunkMap.resize(Header->NumThunks);
+ if (auto EC = Reader.readArray<uint32_t>(ThunkMap))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Could not read a thunk map.");
+
+ // Something called "section map" follows.
+ std::vector<SectionOffset> SectionMap(Header->NumSections);
+ if (auto EC = Reader.readArray<SectionOffset>(SectionMap))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Could not read a section map.");
+
+ if (Reader.bytesRemaining() > 0)
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Corrupted publics stream.");
return Error::success();
}
OpenPOWER on IntegriCloud