Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1145)

Unified Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 495593003: Avoid memory corruption in sessions sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
diff --git a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
index 5bee6292186351386c31b801e34fc3c7611fc1c0..925d8177401c0985a97a074fca0d2471592b05c4 100644
--- a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
+++ b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
@@ -1930,4 +1930,78 @@ TEST_F(SessionsSyncManagerTest, NotifiedOfRefresh) {
}
#endif // defined(OS_ANDROID) || defined(OS_IOS)
+// Tests receipt of duplicate tab IDs in the same window. This should never
+// happen, but we want to make sure the client won't do anything bad if it does
+// receive such garbage input data.
+TEST_F(SessionsSyncManagerTest, ReceiveDuplicateTabInSameWindow) {
+ std::string tag = "tag1";
+
+ // Reuse tab ID 10 in an attempt to trigger bad behavior.
+ SessionID::id_type n1[] = {5, 10, 10, 17};
+ std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
+ std::vector<sync_pb::SessionSpecifics> tabs1;
+ sync_pb::SessionSpecifics meta(
+ helper()->BuildForeignSession(tag, tab_list1, &tabs1));
+
+ // Set up initial data.
+ syncer::SyncDataList initial_data;
+ sync_pb::EntitySpecifics entity;
+ entity.mutable_session()->CopyFrom(meta);
+ initial_data.push_back(SyncData::CreateRemoteData(
+ 1,
+ entity,
+ base::Time(),
+ syncer::AttachmentIdList(),
+ syncer::AttachmentServiceProxyForTest::Create()));
+ AddTabsToSyncDataList(tabs1, &initial_data);
+
+ syncer::SyncChangeList output;
+ InitWithSyncDataTakeOutput(initial_data, &output);
+}
+
+// Tests receipt of duplicate tab IDs for the same session. The duplicate tab
+// ID is present in two different windows. A client can't be expected to do
+// anything reasonable with this input, but we can expect that it doesn't
+// crash.
+TEST_F(SessionsSyncManagerTest, ReceiveDuplicateTabInOtherWindow) {
+ std::string tag = "tag1";
+
+ SessionID::id_type n1[] = {5, 10, 17};
+ std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
+ std::vector<sync_pb::SessionSpecifics> tabs1;
+ sync_pb::SessionSpecifics meta(
+ helper()->BuildForeignSession(tag, tab_list1, &tabs1));
+
+ // Add a second window. Tab ID 10 is a duplicate.
+ SessionID::id_type n2[] = {10, 18, 20};
+ std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2));
+ helper()->AddWindowSpecifics(1, tab_list2, &meta);
+
+ // Set up initial data.
+ syncer::SyncDataList initial_data;
+ sync_pb::EntitySpecifics entity;
+ entity.mutable_session()->CopyFrom(meta);
+ initial_data.push_back(SyncData::CreateRemoteData(
+ 1,
+ entity,
+ base::Time(),
+ syncer::AttachmentIdList(),
+ syncer::AttachmentServiceProxyForTest::Create()));
+ AddTabsToSyncDataList(tabs1, &initial_data);
+
+ for (size_t i = 0; i < tab_list2.size(); ++i) {
+ sync_pb::EntitySpecifics entity;
+ helper()->BuildTabSpecifics(tag, 0, tab_list2[i], entity.mutable_session());
+ initial_data.push_back(SyncData::CreateRemoteData(
+ i + 10,
+ entity,
+ base::Time(),
+ syncer::AttachmentIdList(),
+ syncer::AttachmentServiceProxyForTest::Create()));
+ }
+
+ syncer::SyncChangeList output;
+ InitWithSyncDataTakeOutput(initial_data, &output);
+}
+
} // namespace browser_sync
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698