RLP edge case bug
This commit is contained in:
parent
c100e15580
commit
feebfdbe72
|
@ -832,7 +832,7 @@ public class RLP {
|
|||
|
||||
return srcData;
|
||||
|
||||
} else if (srcData.length <= 0x37) {
|
||||
} else if (srcData.length < 0x37) {
|
||||
// length = 8X
|
||||
byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length);
|
||||
byte[] data = Arrays.copyOf(srcData, srcData.length + 1);
|
||||
|
@ -872,7 +872,7 @@ public class RLP {
|
|||
|
||||
byte[] data;
|
||||
int copyPos = 0;
|
||||
if (totalLength <= 0x37) {
|
||||
if (totalLength < 0x37) {
|
||||
|
||||
data = new byte[1 + totalLength];
|
||||
data[0] = (byte) (OFFSET_SHORT_LIST + totalLength);
|
||||
|
|
|
@ -758,4 +758,22 @@ public class RLPTest {
|
|||
oos.close();
|
||||
return baos.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test // found this with a bug - nice to keep
|
||||
public void encodeEdgeShortList(){
|
||||
|
||||
String expectedOutput = "f837c0c0b4600160003556601359506301000000600035040f6018590060005660805460016080530160005760003560805760203560003557";
|
||||
|
||||
byte[] rlpKeysList = Hex.decode("c0");
|
||||
byte[] rlpValuesList = Hex.decode("c0");
|
||||
byte[] rlpCode = Hex.decode("b4600160003556601359506301000000600035040f6018590060005660805460016080530160005760003560805760203560003557");
|
||||
byte[] output = RLP.encodeList(rlpKeysList, rlpValuesList, rlpCode);
|
||||
|
||||
assertEquals(expectedOutput, Hex.toHexString(output));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue