Dictionary: add defensive coding checks.

This commit is contained in:
Kyle Isom 2023-10-19 21:00:21 -07:00
parent 0a661a7d70
commit 6dab443789
1 changed files with 9 additions and 1 deletions

View File

@ -158,6 +158,10 @@ operator<<(std::ostream &os, const Dictionary &dictionary)
uint8_t *cursor = (dictionary.arena).Start(); uint8_t *cursor = (dictionary.arena).Start();
TLV::Record rec; TLV::Record rec;
if (cursor == nullptr) {
return os;
}
TLV::ReadFromMemory(rec, cursor); TLV::ReadFromMemory(rec, cursor);
if (rec.Tag == TLV::TAG_EMPTY) { if (rec.Tag == TLV::TAG_EMPTY) {
os << "\t(NONE)" << std::endl; os << "\t(NONE)" << std::endl;
@ -168,7 +172,11 @@ operator<<(std::ostream &os, const Dictionary &dictionary)
os << "\t" << rec.Val << "->"; os << "\t" << rec.Val << "->";
cursor = TLV::SkipRecord(rec, cursor); cursor = TLV::SkipRecord(rec, cursor);
TLV::ReadFromMemory(rec, cursor); TLV::ReadFromMemory(rec, cursor);
os << rec.Val << std::endl; if (cursor == nullptr) {
os << "*** CORRUPT DICTIONARY ***\n";
break;
}
os << rec.Val << "\n";
cursor = TLV::SkipRecord(rec, cursor); cursor = TLV::SkipRecord(rec, cursor);
TLV::ReadFromMemory(rec, cursor); TLV::ReadFromMemory(rec, cursor);
} }