win: Fix debug iterator failure on empty database read/write

R=mark@chromium.org, rsesek@chromium.org
BUG=crashpad:80

Review URL: https://codereview.chromium.org/1492503002 .
This commit is contained in:
Scott Graham 2015-12-01 10:33:24 -08:00
parent 7764fa1144
commit 72d6be5cb9
2 changed files with 53 additions and 17 deletions

View File

@ -555,6 +555,36 @@ TEST_F(CrashReportDatabaseTest, DeleteReport) {
db()->LookUpCrashReport(keep_completed.uuid, &keep_completed));
}
TEST_F(CrashReportDatabaseTest, DeleteReportEmptyingDatabase) {
CrashReportDatabase::Report report;
CreateCrashReport(&report);
EXPECT_TRUE(FileExists(report.file_path));
UploadReport(report.uuid, true, "1");
EXPECT_EQ(CrashReportDatabase::kNoError,
db()->LookUpCrashReport(report.uuid, &report));
EXPECT_TRUE(FileExists(report.file_path));
// This causes an empty database to be written, make sure this is handled.
EXPECT_EQ(CrashReportDatabase::kNoError, db()->DeleteReport(report.uuid));
EXPECT_FALSE(FileExists(report.file_path));
}
TEST_F(CrashReportDatabaseTest, ReadEmptyDatabase) {
CrashReportDatabase::Report report;
CreateCrashReport(&report);
EXPECT_EQ(CrashReportDatabase::kNoError, db()->DeleteReport(report.uuid));
// Deleting and the creating another report causes an empty database to be
// loaded. Make sure this is handled.
CrashReportDatabase::Report report2;
CreateCrashReport(&report2);
}
} // namespace
} // namespace test
} // namespace crashpad

View File

@ -417,8 +417,11 @@ void Metadata::Read() {
return;
}
std::vector<ReportDisk> reports;
if (header.num_records > 0) {
std::vector<MetadataFileReportRecord> records(header.num_records);
if (!LoggingReadFile(handle_.get(), &records[0], records_size.ValueOrDie())) {
if (!LoggingReadFile(
handle_.get(), &records[0], records_size.ValueOrDie())) {
LOG(ERROR) << "failed to read records";
return;
}
@ -429,7 +432,6 @@ void Metadata::Read() {
return;
}
std::vector<ReportDisk> reports;
for (const auto& record : records) {
if (record.file_path_index >= string_table.size() ||
record.id_index >= string_table.size()) {
@ -438,6 +440,7 @@ void Metadata::Read() {
}
reports.push_back(ReportDisk(record, report_dir_, string_table));
}
}
reports_.swap(reports);
}
@ -466,6 +469,9 @@ void Metadata::Write() {
return;
}
if (num_records == 0)
return;
// Build the records and string table we're going to write.
std::string string_table;
std::vector<MetadataFileReportRecord> records;