Skip to content

Commit d822402

Browse files
committed
trie: fix error in node decoding
1 parent 5b8ae78 commit d822402

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

trie/encoding.go

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func hexToCompact(hex []byte) []byte {
5252
}
5353

5454
func compactToHex(compact []byte) []byte {
55+
if len(compact) == 0 {
56+
return compact
57+
}
5558
base := keybytesToHex(compact)
5659
// delete terminator flag
5760
if base[0] < 2 {

trie/trie_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,16 @@ func updateString(trie *Trie, k, v string) {
614614
func deleteString(trie *Trie, k string) {
615615
trie.Delete([]byte(k))
616616
}
617+
618+
func TestDecodeNode(t *testing.T) {
619+
t.Parallel()
620+
var (
621+
hash = make([]byte, 20)
622+
elems = make([]byte, 20)
623+
)
624+
for i := 0; i < 5000000; i++ {
625+
rand.Read(hash)
626+
rand.Read(elems)
627+
decodeNode(hash, elems, 1)
628+
}
629+
}

0 commit comments

Comments
 (0)