Skip to content

Commit

Permalink
rlp: fix decoding long strings into RawValue types
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Aug 24, 2017
1 parent 3c48a25 commit 63246e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rlp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (s *Stream) Raw() ([]byte, error) {
return nil, err
}
if kind == String {
puthead(buf, 0x80, 0xB8, size)
puthead(buf, 0x80, 0xB7, size)
} else {
puthead(buf, 0xC0, 0xF7, size)
}
Expand Down
35 changes: 25 additions & 10 deletions rlp/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,31 @@ func TestStreamList(t *testing.T) {
}

func TestStreamRaw(t *testing.T) {
s := NewStream(bytes.NewReader(unhex("C58401010101")), 0)
s.List()

want := unhex("8401010101")
raw, err := s.Raw()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(want, raw) {
t.Errorf("raw mismatch: got %x, want %x", raw, want)
tests := []struct {
input string
output string
}{
{
"C58401010101",
"8401010101",
},
{
"F842B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
"B84001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
},
}
for i, tt := range tests {
s := NewStream(bytes.NewReader(unhex(tt.input)), 0)
s.List()

want := unhex(tt.output)
raw, err := s.Raw()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(want, raw) {
t.Errorf("test %d: raw mismatch: got %x, want %x", i, raw, want)
}
}
}

Expand Down

0 comments on commit 63246e2

Please sign in to comment.