Message: remove check against max message size in checkReadLength()

Checking against the remaining bytes in the payload should be enough.
The payload can't be longer than max message size.
This commit is contained in:
Andreas Schildbach 2023-03-24 16:12:45 +01:00
parent 9b3b11fd0f
commit b39ad1904d

View file

@ -32,6 +32,7 @@ import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import static org.bitcoinj.base.internal.Preconditions.check;
import static org.bitcoinj.base.internal.Preconditions.checkArgument;
import static org.bitcoinj.base.internal.Preconditions.checkState;
@ -164,9 +165,7 @@ public abstract class Message {
}
private void checkReadLength(int length) throws BufferUnderflowException {
if ((length > MAX_SIZE) || length > payload.remaining()) {
throw new BufferUnderflowException();
}
check(length <= payload.remaining(), BufferUnderflowException::new);
}
protected byte[] readBytes(int length) throws BufferUnderflowException {