Commit 719003e5 authored by Anqing Zhao's avatar Anqing Zhao Committed by Commit Bot

Ignore unexpected single-column entry in uploads.log

There are two kind of formats used in the crash logging file.
- [CSV format] the old version to deprecate.
- [JSON format] the new version with better extensibility.

To decide the format of a specific log entry. We should make sure it is
not only a JSON type, but also a JSON dictionary type. Otherwise the
invalid CSV entry with single column will be wrongly treated as JSON
format, then enter the parsing logic. It may cause unexpected crash.

Bug: 1142529
Change-Id: I899940eece378b0359188dc14d617fb0570dedfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538216Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Anqing Zhao <anqing@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829305}
parent f3edc446
......@@ -240,7 +240,7 @@ void TextLogUploadList::ParseLogEntries(
std::unique_ptr<UploadInfo> info = nullptr;
base::Optional<base::Value> json = base::JSONReader::Read(line);
if (json.has_value())
if (json.has_value() && json->is_dict())
info = TryParseJsonLogEntry(json.value());
else
info = TryParseCsvLogEntry(line);
......
......@@ -596,6 +596,34 @@ TEST_F(TextLogUploadListTest, SkipInvalidEntry_JSON) {
EXPECT_EQ(1u, uploads.size());
}
// Test log entry string with only single column.
// Such kind of lines are considered as invalid CSV entry. They should be
// skipped in parsing the log file.
TEST_F(TextLogUploadListTest, SkipBlankOrCorruptedEntry) {
std::string test_entry;
// Add an empty line.
test_entry += "\n";
// Add a line with only single column.
test_entry.append(kTestUploadTime);
test_entry += "\n";
WriteUploadLog(test_entry);
scoped_refptr<TextLogUploadList> upload_list =
new TextLogUploadList(log_path());
base::RunLoop run_loop;
upload_list->Load(run_loop.QuitClosure());
run_loop.Run();
std::vector<UploadList::UploadInfo> uploads;
upload_list->GetUploads(999, &uploads);
EXPECT_EQ(0u, uploads.size());
}
TEST_F(TextLogUploadListTest, ClearUsingUploadTime) {
constexpr time_t kTestTime = 1234u;
constexpr char kOtherEntry[] = "4567,def\n";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment