Files
briar/components/net/sf/briar/protocol/MessageIdReader.java
akwizgran c90a18278b Allow a maximum length to be specified when reading strings or byte
arrays, check it before allocating the buffer, and always specify the
maximum length when reading untrusted data - otherwise
CountingConsumer will reject the packet, but not before we've tried to
allocate a buffer of the specified size (up to 2 GB).
2011-08-03 19:29:30 +01:00

21 lines
619 B
Java

package net.sf.briar.protocol;
import java.io.IOException;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Tags;
import net.sf.briar.api.protocol.UniqueId;
import net.sf.briar.api.serial.FormatException;
import net.sf.briar.api.serial.ObjectReader;
import net.sf.briar.api.serial.Reader;
class MessageIdReader implements ObjectReader<MessageId> {
public MessageId readObject(Reader r) throws IOException {
r.readUserDefinedTag(Tags.MESSAGE_ID);
byte[] b = r.readBytes(UniqueId.LENGTH);
if(b.length != UniqueId.LENGTH) throw new FormatException();
return new MessageId(b);
}
}