diff --git a/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java b/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java index f9db08a2668ae8f8a851c6f2959f3cab1ce73e00..983be4a049d0fb9e82fc37d2c465c6576d32cff9 100644 --- a/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java +++ b/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java @@ -7,10 +7,13 @@ import static org.briarproject.api.messaging.Types.SUBSCRIPTION_UPDATE; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.briarproject.api.FormatException; import org.briarproject.api.messaging.Group; +import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.serial.Consumer; import org.briarproject.api.serial.CountingConsumer; @@ -31,11 +34,15 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> { r.addConsumer(counting); // Read the start of the struct r.readStructStart(SUBSCRIPTION_UPDATE); - // Read the subscriptions + // Read the subscriptions, rejecting duplicates List<Group> groups = new ArrayList<Group>(); + Set<GroupId> ids = new HashSet<GroupId>(); r.readListStart(); - for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) - groups.add(groupReader.readStruct(r)); + for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) { + Group g = groupReader.readStruct(r); + if(!ids.add(g.getId())) throw new FormatException(); // Duplicate + groups.add(g); + } r.readListEnd(); // Read the version number long version = r.readInteger();