@@ -93,12 +93,16 @@ func TestStreamErrors(t *testing.T) {
9393 {"00" , calls {"ListEnd" }, nil , errNotInList },
9494 {"C401020304" , calls {"List" , "Uint" , "ListEnd" }, nil , errNotAtEOL },
9595
96- // Leading zero bytes are rejected when reading integers .
96+ // Non-canonical integers (e.g. leading zero bytes) .
9797 {"00" , calls {"Uint" }, nil , ErrCanonInt },
9898 {"820002" , calls {"Uint" }, nil , ErrCanonInt },
99+ {"8133" , calls {"Uint" }, nil , ErrCanonSize },
100+ {"8156" , calls {"Uint" }, nil , nil },
99101
100102 // Size tags must use the smallest possible encoding.
101103 // Leading zero bytes in the size tag are also rejected.
104+ {"8100" , calls {"Uint" }, nil , ErrCanonSize },
105+ {"8100" , calls {"Bytes" }, nil , ErrCanonSize },
102106 {"B800" , calls {"Kind" }, withoutInputLimit , ErrCanonSize },
103107 {"B90000" , calls {"Kind" }, withoutInputLimit , ErrCanonSize },
104108 {"B90055" , calls {"Kind" }, withoutInputLimit , ErrCanonSize },
@@ -112,7 +116,7 @@ func TestStreamErrors(t *testing.T) {
112116 {"" , calls {"Kind" }, nil , io .EOF },
113117 {"" , calls {"Uint" }, nil , io .EOF },
114118 {"" , calls {"List" }, nil , io .EOF },
115- {"8105 " , calls {"Uint" , "Uint" }, nil , io .EOF },
119+ {"8158 " , calls {"Uint" , "Uint" }, nil , io .EOF },
116120 {"C0" , calls {"List" , "ListEnd" , "List" }, nil , io .EOF },
117121
118122 // Input limit errors.
@@ -129,11 +133,11 @@ func TestStreamErrors(t *testing.T) {
129133 // down toward zero in Stream.remaining, reading too far can overflow
130134 // remaining to a large value, effectively disabling the limit.
131135 {"C40102030401" , calls {"Raw" , "Uint" }, withCustomInputLimit (5 ), io .EOF },
132- {"C4010203048102 " , calls {"Raw" , "Uint" }, withCustomInputLimit (6 ), ErrValueTooLarge },
136+ {"C4010203048158 " , calls {"Raw" , "Uint" }, withCustomInputLimit (6 ), ErrValueTooLarge },
133137
134138 // Check that the same calls are fine without a limit.
135139 {"C40102030401" , calls {"Raw" , "Uint" }, withoutInputLimit , nil },
136- {"C4010203048102 " , calls {"Raw" , "Uint" }, withoutInputLimit , nil },
140+ {"C4010203048158 " , calls {"Raw" , "Uint" }, withoutInputLimit , nil },
137141
138142 // Unexpected EOF. This only happens when there is
139143 // no input limit, so the reader needs to be 'dumbed down'.
@@ -295,13 +299,13 @@ var decodeTests = []decodeTest{
295299 // integers
296300 {input : "05" , ptr : new (uint32 ), value : uint32 (5 )},
297301 {input : "80" , ptr : new (uint32 ), value : uint32 (0 )},
298- {input : "8105" , ptr : new (uint32 ), value : uint32 (5 )},
299302 {input : "820505" , ptr : new (uint32 ), value : uint32 (0x0505 )},
300303 {input : "83050505" , ptr : new (uint32 ), value : uint32 (0x050505 )},
301304 {input : "8405050505" , ptr : new (uint32 ), value : uint32 (0x05050505 )},
302305 {input : "850505050505" , ptr : new (uint32 ), error : "rlp: input string too long for uint32" },
303306 {input : "C0" , ptr : new (uint32 ), error : "rlp: expected input string or byte for uint32" },
304307 {input : "00" , ptr : new (uint32 ), error : "rlp: non-canonical integer (leading zero bytes) for uint32" },
308+ {input : "8105" , ptr : new (uint32 ), error : "rlp: non-canonical size information for uint32" },
305309 {input : "820004" , ptr : new (uint32 ), error : "rlp: non-canonical integer (leading zero bytes) for uint32" },
306310 {input : "B8020004" , ptr : new (uint32 ), error : "rlp: non-canonical size information for uint32" },
307311
@@ -319,10 +323,16 @@ var decodeTests = []decodeTest{
319323 // byte slices
320324 {input : "01" , ptr : new ([]byte ), value : []byte {1 }},
321325 {input : "80" , ptr : new ([]byte ), value : []byte {}},
326+
322327 {input : "8D6162636465666768696A6B6C6D" , ptr : new ([]byte ), value : []byte ("abcdefghijklm" )},
323328 {input : "C0" , ptr : new ([]byte ), value : []byte {}},
324329 {input : "C3010203" , ptr : new ([]byte ), value : []byte {1 , 2 , 3 }},
325330
331+ {
332+ input : "8105" ,
333+ ptr : new ([]byte ),
334+ error : "rlp: non-canonical size information for []uint8" ,
335+ },
326336 {
327337 input : "C3820102" ,
328338 ptr : new ([]byte ),
@@ -346,10 +356,15 @@ var decodeTests = []decodeTest{
346356 ptr : new ([5 ]byte ),
347357 error : "rlp: input string too long for [5]uint8" ,
348358 },
359+ {
360+ input : "8105" ,
361+ ptr : new ([5 ]byte ),
362+ error : "rlp: non-canonical size information for [5]uint8" ,
363+ },
349364
350365 // byte array reuse (should be zeroed)
351366 {input : "850102030405" , ptr : & sharedByteArray , value : [5 ]byte {1 , 2 , 3 , 4 , 5 }},
352- {input : "8101 " , ptr : & sharedByteArray , value : [5 ]byte {1 }}, // kind: String
367+ {input : "01 " , ptr : & sharedByteArray , value : [5 ]byte {1 }}, // kind: String
353368 {input : "850102030405" , ptr : & sharedByteArray , value : [5 ]byte {1 , 2 , 3 , 4 , 5 }},
354369 {input : "01" , ptr : & sharedByteArray , value : [5 ]byte {1 }}, // kind: Byte
355370 {input : "C3010203" , ptr : & sharedByteArray , value : [5 ]byte {1 , 2 , 3 , 0 , 0 }},
@@ -369,9 +384,10 @@ var decodeTests = []decodeTest{
369384 // big ints
370385 {input : "01" , ptr : new (* big.Int ), value : big .NewInt (1 )},
371386 {input : "89FFFFFFFFFFFFFFFFFF" , ptr : new (* big.Int ), value : veryBigInt },
372- {input : "820001" , ptr : new (big.Int ), error : "rlp: non-canonical integer (leading zero bytes) for *big.Int" },
373387 {input : "10" , ptr : new (big.Int ), value : * big .NewInt (16 )}, // non-pointer also works
374388 {input : "C0" , ptr : new (* big.Int ), error : "rlp: expected input string or byte for *big.Int" },
389+ {input : "820001" , ptr : new (big.Int ), error : "rlp: non-canonical integer (leading zero bytes) for *big.Int" },
390+ {input : "8105" , ptr : new (big.Int ), error : "rlp: non-canonical size information for *big.Int" },
375391
376392 // structs
377393 {input : "C0" , ptr : new (simplestruct ), value : simplestruct {0 , "" }},
@@ -404,7 +420,7 @@ var decodeTests = []decodeTest{
404420 {input : "80" , ptr : new (* uint ), value : (* uint )(nil )},
405421 {input : "C0" , ptr : new (* uint ), value : (* uint )(nil )},
406422 {input : "07" , ptr : new (* uint ), value : uintp (7 )},
407- {input : "8108 " , ptr : new (* uint ), value : uintp (8 )},
423+ {input : "8158 " , ptr : new (* uint ), value : uintp (0x58 )},
408424 {input : "C109" , ptr : new (* []uint ), value : & []uint {9 }},
409425 {input : "C58403030303" , ptr : new (* [][]byte ), value : & [][]byte {{3 , 3 , 3 , 3 }}},
410426
0 commit comments