diff --git a/core/src/main/java/org/bitcoinj/core/Message.java b/core/src/main/java/org/bitcoinj/core/Message.java index e6f5cd2be3a..fea88cf5d90 100644 --- a/core/src/main/java/org/bitcoinj/core/Message.java +++ b/core/src/main/java/org/bitcoinj/core/Message.java @@ -327,7 +327,7 @@ protected long readVarInt(int offset) throws ProtocolException { } protected byte[] readBytes(int length) throws ProtocolException { - if (length > MAX_SIZE) { + if ((length > MAX_SIZE) || (cursor + length > payload.length)) { throw new ProtocolException("Claimed value length too large: " + length); } try {