summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp50
1 files changed, 38 insertions, 12 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
index 28dc67a9d2a..b3bd94cda90 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
@@ -9,6 +9,7 @@
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/DebugInfo/PDB/Raw/RawError.h"
#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"
using namespace llvm;
@@ -16,12 +17,17 @@ using namespace llvm::pdb;
NameMap::NameMap() {}
-std::error_code NameMap::load(StreamReader &Stream) {
+Error NameMap::load(StreamReader &Stream) {
// This is some sort of weird string-set/hash table encoded in the stream.
// It starts with the number of bytes in the table.
uint32_t NumberOfBytes;
- Stream.readInteger(NumberOfBytes);
+ if (Stream.readInteger(NumberOfBytes))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map length");
+ if (Stream.bytesRemaining() < NumberOfBytes)
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Invalid name map length");
// Following that field is the starting offset of strings in the name table.
uint32_t StringsOffset = Stream.getOffset();
@@ -30,36 +36,50 @@ std::error_code NameMap::load(StreamReader &Stream) {
// This appears to be equivalent to the total number of strings *actually*
// in the name table.
uint32_t HashSize;
- Stream.readInteger(HashSize);
+ if (Stream.readInteger(HashSize))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map hash size");
// This appears to be an upper bound on the number of strings in the name
// table.
uint32_t MaxNumberOfStrings;
- Stream.readInteger(MaxNumberOfStrings);
+ if (Stream.readInteger(MaxNumberOfStrings))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map max strings");
// This appears to be a hash table which uses bitfields to determine whether
// or not a bucket is 'present'.
uint32_t NumPresentWords;
- Stream.readInteger(NumPresentWords);
+ if (Stream.readInteger(NumPresentWords))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map num words");
// Store all the 'present' bits in a vector for later processing.
SmallVector<uint32_t, 1> PresentWords;
for (uint32_t I = 0; I != NumPresentWords; ++I) {
uint32_t Word;
- Stream.readInteger(Word);
+ if (Stream.readInteger(Word))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map word");
+
PresentWords.push_back(Word);
}
// This appears to be a hash table which uses bitfields to determine whether
// or not a bucket is 'deleted'.
uint32_t NumDeletedWords;
- Stream.readInteger(NumDeletedWords);
+ if (Stream.readInteger(NumDeletedWords))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map num deleted words");
// Store all the 'deleted' bits in a vector for later processing.
SmallVector<uint32_t, 1> DeletedWords;
for (uint32_t I = 0; I != NumDeletedWords; ++I) {
uint32_t Word;
- Stream.readInteger(Word);
+ if (Stream.readInteger(Word))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map deleted word");
+
DeletedWords.push_back(Word);
}
@@ -79,11 +99,15 @@ std::error_code NameMap::load(StreamReader &Stream) {
// This appears to be an offset relative to the start of the strings.
// It tells us where the null-terminated string begins.
uint32_t NameOffset;
- Stream.readInteger(NameOffset);
+ if (Stream.readInteger(NameOffset))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map name offset");
// This appears to be a stream number into the stream directory.
uint32_t NameIndex;
- Stream.readInteger(NameIndex);
+ if (Stream.readInteger(NameIndex))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map name index");
// Compute the offset of the start of the string relative to the stream.
uint32_t StringOffset = StringsOffset + NameOffset;
@@ -91,14 +115,16 @@ std::error_code NameMap::load(StreamReader &Stream) {
// Pump out our c-string from the stream.
std::string Str;
Stream.setOffset(StringOffset);
- Stream.readZeroString(Str);
+ if (Stream.readZeroString(Str))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Expected name map name");
Stream.setOffset(OldOffset);
// Add this to a string-map from name to stream number.
Mapping.insert({Str, NameIndex});
}
- return std::error_code();
+ return Error::success();
}
bool NameMap::tryGetValue(StringRef Name, uint32_t &Value) const {
OpenPOWER on IntegriCloud