diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java index 51878f00ba..94347322ff 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncHelper.java @@ -74,7 +74,6 @@ public final class StorageSyncHelper { * @return If changes need to be written, then it will return those changes. If no changes need * to be written, this will return {@link Optional#absent()}. */ - // TODO [greyson] [storage] Test this public static @NonNull Optional buildStorageUpdatesForLocal(long currentManifestVersion, @NonNull List currentLocalKeys, @NonNull List updates, diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java index 14028adaa0..8ce103350b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java @@ -13,6 +13,7 @@ import org.whispersystems.signalservice.api.storage.SignalStorageRecord; import org.whispersystems.signalservice.api.storage.StorageId; import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord; +import java.nio.ByteBuffer; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -42,8 +43,17 @@ public final class StorageSyncValidations { } private static void validateManifestAndInserts(@NonNull SignalStorageManifest manifest, @NonNull List inserts) { - Set allSet = new HashSet<>(manifest.getStorageIds()); - Set insertSet = new HashSet<>(Stream.of(inserts).map(SignalStorageRecord::getId).toList()); + Set allSet = new HashSet<>(manifest.getStorageIds()); + Set insertSet = new HashSet<>(Stream.of(inserts).map(SignalStorageRecord::getId).toList()); + Set rawIdSet = Stream.of(allSet).map(id -> ByteBuffer.wrap(id.getRaw())).collect(Collectors.toSet()); + + if (allSet.size() != manifest.getStorageIds().size()) { + throw new DuplicateStorageIdError(); + } + + if (rawIdSet.size() != allSet.size()) { + throw new DuplicateRawIdError(); + } int accountCount = 0; for (StorageId id : manifest.getStorageIds()) { @@ -81,6 +91,12 @@ public final class StorageSyncValidations { } } + private static final class DuplicateStorageIdError extends Error { + } + + private static final class DuplicateRawIdError extends Error { + } + private static final class DuplicateInsertInWriteError extends Error { }