Skip to content

Commit

Permalink
Fix rlp validate to handle lists ending at the start of another list (h…
Browse files Browse the repository at this point in the history
…yperledger#8143)

* 8053: Add RLPDecodingHelpers.Kind.EM
and handle empty lists in AbstractRLPInput

Signed-off-by: Matilda Clerke <[email protected]>

* Revert previous change, implement new fix

Signed-off-by: Matilda Clerke <[email protected]>

* Revert previous change, implement new fix

Signed-off-by: Matilda Clerke <[email protected]>

---------

Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke authored Jan 21, 2025
1 parent 702ce74 commit 5933a2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5933a2a

Please sign in to comment.