[llvm] r269381 - [codeview] Try to handle errors better in record iterator
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 16:26:23 PDT 2016
Author: rnk
Date: Thu May 12 18:26:23 2016
New Revision: 269381
URL: http://llvm.org/viewvc/llvm-project?rev=269381&view=rev
Log:
[codeview] Try to handle errors better in record iterator
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
llvm/trunk/include/llvm/DebugInfo/CodeView/RecordIterator.h
llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h
llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h Thu May 12 18:26:23 2016
@@ -78,7 +78,7 @@ public:
/// Visits the type records in Data. Sets the error flag on parse failures.
void visitTypeStream(ArrayRef<uint8_t> Data) {
- for (const auto &I : makeTypeRange(Data)) {
+ for (const auto &I : makeTypeRange(Data, &HadError)) {
visitTypeRecord(I);
if (hadError())
break;
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/RecordIterator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/RecordIterator.h?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/RecordIterator.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/RecordIterator.h Thu May 12 18:26:23 2016
@@ -31,12 +31,12 @@ public:
ArrayRef<uint8_t> Data;
};
- explicit RecordIterator(const ArrayRef<uint8_t> &RecordBytes)
- : Data(RecordBytes), AtEnd(false) {
+ explicit RecordIterator(const ArrayRef<uint8_t> &RecordBytes, bool *HadError)
+ : HadError(HadError), Data(RecordBytes), AtEnd(false) {
next(); // Prime the pump
}
- RecordIterator() : AtEnd(true) {}
+ RecordIterator() : HadError(nullptr), AtEnd(true) {}
// For iterators to compare equal, they must both point at the same record
// in the same data stream, or they must both be at the end of a stream.
@@ -82,13 +82,16 @@ private:
// FIXME: Use consumeObject when it deals in ArrayRef<uint8_t>.
if (Data.size() < sizeof(RecordPrefix))
- return;
+ return parseError();
const auto *Rec = reinterpret_cast<const RecordPrefix *>(Data.data());
Data = Data.drop_front(sizeof(RecordPrefix));
Current.Length = Rec->RecordLen;
Current.Type = static_cast<Kind>(uint16_t(Rec->RecordKind));
- Current.Data = Data.slice(0, Current.Length - 2);
+ size_t RecLen = Current.Length - 2;
+ if (RecLen > Data.size())
+ return parseError();
+ Current.Data = Data.slice(0, RecLen);
// The next record starts immediately after this one.
Data = Data.drop_front(Current.Data.size());
@@ -100,6 +103,12 @@ private:
return;
}
+ void parseError() {
+ if (HadError)
+ *HadError = true;
+ }
+
+ bool *HadError;
ArrayRef<uint8_t> Data;
Record Current;
bool AtEnd;
@@ -107,8 +116,8 @@ private:
template <typename Kind>
inline iterator_range<RecordIterator<Kind>>
-makeRecordRange(ArrayRef<uint8_t> Data) {
- return make_range(RecordIterator<Kind>(Data), RecordIterator<Kind>());
+makeRecordRange(ArrayRef<uint8_t> Data, bool *HadError) {
+ return make_range(RecordIterator<Kind>(Data, HadError), RecordIterator<Kind>());
}
}
}
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h Thu May 12 18:26:23 2016
@@ -329,7 +329,7 @@ struct ThreadLocalDataSym {
typedef RecordIterator<SymbolRecordKind> SymbolIterator;
inline iterator_range<SymbolIterator> makeSymbolRange(ArrayRef<uint8_t> Data) {
- return make_range(SymbolIterator(Data), SymbolIterator());
+ return make_range(SymbolIterator(Data, nullptr), SymbolIterator());
}
} // namespace codeview
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStream.h?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStream.h Thu May 12 18:26:23 2016
@@ -27,8 +27,8 @@ namespace codeview {
typedef RecordIterator<TypeLeafKind> TypeIterator;
-inline iterator_range<TypeIterator> makeTypeRange(ArrayRef<uint8_t> Data) {
- return make_range(TypeIterator(Data), TypeIterator());
+inline iterator_range<TypeIterator> makeTypeRange(ArrayRef<uint8_t> Data, bool *HadError) {
+ return make_range(TypeIterator(Data, HadError), TypeIterator());
}
} // end namespace codeview
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h Thu May 12 18:26:23 2016
@@ -38,7 +38,7 @@ public:
uint32_t TypeIndexEnd() const;
uint32_t NumTypeRecords() const;
- iterator_range<codeview::TypeIterator> types() const;
+ iterator_range<codeview::TypeIterator> types(bool *HadError) const;
private:
PDBFile &Pdb;
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp Thu May 12 18:26:23 2016
@@ -129,6 +129,6 @@ uint32_t TpiStream::NumTypeRecords() con
return TypeIndexEnd() - TypeIndexBegin();
}
-iterator_range<codeview::TypeIterator> TpiStream::types() const {
- return codeview::makeTypeRange(RecordsBuffer.data());
+iterator_range<codeview::TypeIterator> TpiStream::types(bool *HadError) const {
+ return codeview::makeTypeRange(RecordsBuffer.data(), /*HadError=*/HadError);
}
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=269381&r1=269380&r2=269381&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Thu May 12 18:26:23 2016
@@ -44,6 +44,7 @@
#include "llvm/DebugInfo/PDB/Raw/ModStream.h"
#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/DebugInfo/PDB/Raw/RawError.h"
#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"
#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
@@ -376,7 +377,8 @@ static Error dumpTpiStream(ScopedPrinter
ListScope L(P, "Records");
codeview::CVTypeDumper TD(P, false);
- for (auto &Type : Tpi.types()) {
+ bool HadError = false;
+ for (auto &Type : Tpi.types(&HadError)) {
DictScope DD(P, "");
if (opts::DumpTpiRecords)
@@ -385,6 +387,9 @@ static Error dumpTpiStream(ScopedPrinter
if (opts::DumpTpiRecordBytes)
P.printBinaryBlock("Bytes", Type.Data);
}
+ if (HadError)
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "TPI stream contained corrupt record");
}
return Error::success();
}
More information about the llvm-commits
mailing list