Commit 7b8732ab authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Fix access violation in drive sync engine.

The introduction of team drives means that calling
DriveAPIService::GetChangeList can return a ChangeList object that contains both
FileResource and TeamDriveResource entries. The sync engine code is not
TeamDriveResource aware and assumes that ChangeList can only contain
FileResource entries, and calling ChangeResource::File() will return a nullptr
that later causes an AV in PopulateFileDetailsByFileResource.

This CL filters out TeamDriveResource from the ChangeList object. Verified with
new unit test.

Bug: 850228
Change-Id: I1d8f4e8a99df8b8b04683eccaaceae4843020bda
Reviewed-on: https://chromium-review.googlesource.com/1212366
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589826}
parent 304b3521
......@@ -350,5 +350,10 @@ base::FilePath FakeDriveServiceHelper::WriteToTempFile(
return temp_file;
}
void FakeDriveServiceHelper::AddTeamDrive(const std::string& team_drive_id,
const std::string& team_drive_name) {
fake_drive_service_->AddTeamDrive(team_drive_id, team_drive_name);
}
} // namespace drive_backend
} // namespace sync_file_system
......@@ -78,6 +78,9 @@ class FakeDriveServiceHelper {
google_apis::DriveApiErrorCode GetAboutResource(
std::unique_ptr<google_apis::AboutResource>* about_resource);
void AddTeamDrive(const std::string& team_drive_id,
const std::string& team_drive_name);
base::FilePath base_dir_path() { return base_dir_.GetPath(); }
private:
......
......@@ -75,10 +75,23 @@ void ListChangesTask::DidListChanges(
return;
}
change_list_.reserve(change_list_.size() +
change_list->mutable_items()->size());
std::move(change_list->mutable_items()->begin(),
change_list->mutable_items()->end(),
auto* mutable_items = change_list->mutable_items();
// google_apis::ChangeList can contain both FileResource and TeamDriveResource
// entries. We only care about FileResource entries, so filter out any entries
// that are TeamDriveReasource.
mutable_items->erase(
std::remove_if(
mutable_items->begin(), mutable_items->end(),
[](const auto& change_resource) {
return change_resource->type() ==
google_apis::ChangeResource::ChangeType::TEAM_DRIVE;
}),
mutable_items->end());
change_list_.reserve(change_list_.size() + mutable_items->size());
std::move(mutable_items->begin(), mutable_items->end(),
std::back_inserter(change_list_));
change_list->mutable_items()->clear();
......
......@@ -242,5 +242,20 @@ TEST_F(ListChangesTaskTest, UnderTrackedFolder) {
EXPECT_EQ(num_dirty_trackers + 4, CountDirtyTracker());
}
TEST_F(ListChangesTaskTest, TeamDriveChangeInChangeList) {
size_t num_dirty_trackers = CountDirtyTracker();
SetUpChangesInFolder(app_root_folder_id());
// Adding a team drive will return a TeamDriveResource entry when the
// change list is retrieved.
fake_drive_service_helper()->AddTeamDrive("team_drive_id", "team_drive_name");
EXPECT_EQ(SYNC_STATUS_OK, RunTask(std::unique_ptr<SyncTask>(
new ListChangesTask(GetSyncEngineContext()))));
EXPECT_EQ(num_dirty_trackers + 4, CountDirtyTracker());
}
} // namespace drive_backend
} // namespace sync_file_system
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