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
607 B
Java
21 lines
607 B
Java
package net.sf.briar.protocol;
|
|
|
|
import java.io.IOException;
|
|
|
|
import net.sf.briar.api.protocol.BatchId;
|
|
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 BatchIdReader implements ObjectReader<BatchId> {
|
|
|
|
public BatchId readObject(Reader r) throws IOException {
|
|
r.readUserDefinedTag(Tags.BATCH_ID);
|
|
byte[] b = r.readBytes(UniqueId.LENGTH);
|
|
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
|
return new BatchId(b);
|
|
}
|
|
}
|