mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
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).
21 lines
619 B
Java
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);
|
|
}
|
|
}
|