diff --git a/ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLP.java b/ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLP.java index bdd07bf0fbb..b3c18749ddb 100644 --- a/ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLP.java +++ b/ethereum/rlp/src/main/java/org/hyperledger/besu/ethereum/rlp/RLP.java @@ -187,10 +187,11 @@ public static Bytes decodeOne(final Bytes encodedValue) { public static void validate(final Bytes encodedValue) { final RLPInput in = input(encodedValue); while (!in.isDone()) { + while (in.isEndOfCurrentList()) { + in.leaveList(); + } if (in.nextIsList()) { in.enterList(); - } else if (in.isEndOfCurrentList()) { - in.leaveList(); } else { // Skip does as much validation as can be done in general, without allocating anything. in.skipNext(); diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPTest.java b/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPTest.java index a4389cafa98..144e17c55ee 100644 --- a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPTest.java +++ b/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPTest.java @@ -168,6 +168,17 @@ public void calculateSize_overflowMaxRLPStringLength() { .hasMessageContaining("RLP item exceeds max supported size of 2147483647: 2147483648"); } + @Test + public void testValidateWithListEndingAtStartOfList() { + // The structue of the RLP is as shown below + // [ + // ["0x01"], + // ["0x02"] + // ] + Bytes validRlp = Bytes.fromHexString("c4c101c102"); + RLP.validate(validRlp); + } + private static Bytes h(final String hex) { return Bytes.fromHexString(hex); }