Skip to content

Commit 63246e2

Browse files
committed
rlp: fix decoding long strings into RawValue types
1 parent 3c48a25 commit 63246e2

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎rlp/decode.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func (s *Stream) Raw() ([]byte, error) {
693693
return nil, err
694694
}
695695
if kind == String {
696-
puthead(buf, 0x80, 0xB8, size)
696+
puthead(buf, 0x80, 0xB7, size)
697697
} else {
698698
puthead(buf, 0xC0, 0xF7, size)
699699
}

‎rlp/decode_test.go‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,31 @@ func TestStreamList(t *testing.T) {
256256
}
257257

258258
func TestStreamRaw(t *testing.T) {
259-
s := NewStream(bytes.NewReader(unhex("C58401010101")), 0)
260-
s.List()
261-
262-
want := unhex("8401010101")
263-
raw, err := s.Raw()
264-
if err != nil {
265-
t.Fatal(err)
266-
}
267-
if !bytes.Equal(want, raw) {
268-
t.Errorf("raw mismatch: got %x, want %x", raw, want)
259+
tests := []struct {
260+
input string
261+
output string
262+
}{
263+
{
264+
"C58401010101",
265+
"8401010101",
266+
},
267+
{
268+
"F842B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
269+
"B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
270+
},
271+
}
272+
for i, tt := range tests {
273+
s := NewStream(bytes.NewReader(unhex(tt.input)), 0)
274+
s.List()
275+
276+
want := unhex(tt.output)
277+
raw, err := s.Raw()
278+
if err != nil {
279+
t.Fatal(err)
280+
}
281+
if !bytes.Equal(want, raw) {
282+
t.Errorf("test %d: raw mismatch: got %x, want %x", i, raw, want)
283+
}
269284
}
270285
}
271286

0 commit comments

Comments
 (0)