diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-14 02:58:23 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-14 02:58:23 +0000 |
commit | 31aa39ddb62a29bbff6b7073a71d2f513c6e06d7 (patch) | |
tree | c035fcb07a0f494ec4266fa49fa1c83a99bac519 /sync/internal_api | |
parent | 20184248e067fa7d9235c16397f2504cfcf6783a (diff) | |
download | chromium_src-31aa39ddb62a29bbff6b7073a71d2f513c6e06d7.zip chromium_src-31aa39ddb62a29bbff6b7073a71d2f513c6e06d7.tar.gz chromium_src-31aa39ddb62a29bbff6b7073a71d2f513c6e06d7.tar.bz2 |
sync: Improve handling of bad UniquePositions
Makes the client assign a valid position to incoming bookmarks if the
server has not populated the required fields. This code should never be
triggered unless there is a bug in the server. This risks reordering
users' bookmarks, but that's probably preferable to a crash.
Detects bookmarks that do not have valid position information during
database load. If these corrupted bookmarks are detected, the entire
database is declared to be corrupt. Sync will then re-download
all of the user's data, which should fix the problem.
BUG=367247
Review URL: https://codereview.chromium.org/278153002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api')
-rw-r--r-- | sync/internal_api/public/base/unique_position.cc | 11 | ||||
-rw-r--r-- | sync/internal_api/public/base/unique_position.h | 4 |
2 files changed, 14 insertions, 1 deletions
diff --git a/sync/internal_api/public/base/unique_position.cc b/sync/internal_api/public/base/unique_position.cc index 40bab6e..2d41614 100644 --- a/sync/internal_api/public/base/unique_position.cc +++ b/sync/internal_api/public/base/unique_position.cc @@ -6,6 +6,7 @@ #include "base/basictypes.h" #include "base/logging.h" +#include "base/rand_util.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "sync/protocol/unique_position.pb.h" @@ -21,7 +22,8 @@ bool UniquePosition::IsValidSuffix(const std::string& suffix) { // The suffix must be exactly the specified length, otherwise unique suffixes // are not sufficient to guarantee unique positions (because prefix + suffix // == p + refixsuffix). - return suffix.length() == kSuffixLength; + return suffix.length() == kSuffixLength + && suffix[kSuffixLength-1] != 0; } // static. @@ -36,6 +38,13 @@ bool UniquePosition::IsValidBytes(const std::string& bytes) { } // static. +std::string UniquePosition::RandomSuffix() { + // Users random data for all but the last byte. The last byte must not be + // zero. We arbitrarily set it to 0x7f. + return base::RandBytesAsString(kSuffixLength - 1) + "\x7f"; +} + +// static. UniquePosition UniquePosition::CreateInvalid() { UniquePosition pos; DCHECK(!pos.IsValid()); diff --git a/sync/internal_api/public/base/unique_position.h b/sync/internal_api/public/base/unique_position.h index eee5324..b844b82 100644 --- a/sync/internal_api/public/base/unique_position.h +++ b/sync/internal_api/public/base/unique_position.h @@ -46,6 +46,10 @@ class SYNC_EXPORT_PRIVATE UniquePosition { static bool IsValidSuffix(const std::string& suffix); static bool IsValidBytes(const std::string& bytes); + // Returns a valid, but mostly random suffix. + // Avoid using this; it can lead to inconsistent sort orderings if misused. + static std::string RandomSuffix(); + // Returns an invalid position. static UniquePosition CreateInvalid(); |