Skip to content

Commit

Permalink
trie: fix error in node decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Feb 16, 2019
1 parent 5b8ae78 commit d822402
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 d822402

Please sign in to comment.