Don't accept empty acks, batches or offers.

This commit is contained in:
akwizgran
2011-12-07 13:32:17 +00:00
parent 495baf8c70
commit 1c41ffa7af
7 changed files with 143 additions and 32 deletions

View File

@@ -2,7 +2,6 @@ package net.sf.briar.protocol;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -35,9 +34,10 @@ class AckReader implements ObjectReader<Ack> {
r.addConsumer(counting);
r.readStructId(Types.ACK);
r.setMaxBytesLength(UniqueId.LENGTH);
Collection<Bytes> raw = r.readList(Bytes.class);
List<Bytes> raw = r.readList(Bytes.class);
r.resetMaxBytesLength();
r.removeConsumer(counting);
if(raw.isEmpty()) throw new FormatException();
// Convert the byte arrays to batch IDs
List<BatchId> batches = new ArrayList<BatchId>();
for(Bytes b : raw) {

View File

@@ -3,6 +3,7 @@ package net.sf.briar.protocol;
import java.io.IOException;
import java.util.List;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.crypto.CryptoComponent;
import net.sf.briar.api.crypto.MessageDigest;
import net.sf.briar.api.protocol.BatchId;
@@ -44,6 +45,7 @@ class BatchReader implements ObjectReader<UnverifiedBatch> {
r.removeObjectReader(Types.MESSAGE);
r.removeConsumer(digesting);
r.removeConsumer(counting);
if(messages.isEmpty()) throw new FormatException();
// Build and return the batch
BatchId id = new BatchId(messageDigest.digest());
return batchFactory.createUnverifiedBatch(id, messages);

View File

@@ -2,7 +2,6 @@ package net.sf.briar.protocol;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -35,9 +34,10 @@ class OfferReader implements ObjectReader<Offer> {
r.addConsumer(counting);
r.readStructId(Types.OFFER);
r.setMaxBytesLength(UniqueId.LENGTH);
Collection<Bytes> raw = r.readList(Bytes.class);
List<Bytes> raw = r.readList(Bytes.class);
r.resetMaxBytesLength();
r.removeConsumer(counting);
if(raw.isEmpty()) throw new FormatException();
// Convert the byte arrays to message IDs
List<MessageId> messages = new ArrayList<MessageId>();
for(Bytes b : raw) {