Skip to content

Commit

Permalink
trie: fix error in node decoding (ethereum#19111)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored and kiku-jw committed Mar 29, 2019
1 parent ddd9646 commit 36254b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions trie/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func hexToCompact(hex []byte) []byte {
}

func compactToHex(compact []byte) []byte {
if len(compact) == 0 {
return compact
}
base := keybytesToHex(compact)
// delete terminator flag
if base[0] < 2 {
Expand Down
13 changes: 13 additions & 0 deletions trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,16 @@ func updateString(trie *Trie, k, v string) {
func deleteString(trie *Trie, k string) {
trie.Delete([]byte(k))
}

func TestDecodeNode(t *testing.T) {
t.Parallel()
var (
hash = make([]byte, 20)
elems = make([]byte, 20)
)
for i := 0; i < 5000000; i++ {
rand.Read(hash)
rand.Read(elems)
decodeNode(hash, elems, 1)
}
}

0 comments on commit 36254b9

Please sign in to comment.