aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-02-16 23:16:12 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-02-19 16:59:57 +0800
commita458153098d6f66ee0c6f990f31b3646ad171bbb (patch)
tree427e794bdb4c258fa8f8422ecbbcf3a83d44b536
parentfe5258b41ea2e363aea1494dcf52754fea9b42db (diff)
downloaddexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar.gz
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar.bz2
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar.lz
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar.xz
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.tar.zst
dexon-a458153098d6f66ee0c6f990f31b3646ad171bbb.zip
trie: fix error in node decoding (#19111)
-rw-r--r--trie/encoding.go3
-rw-r--r--trie/trie_test.go13
2 files changed, 16 insertions, 0 deletions
diff --git a/trie/encoding.go b/trie/encoding.go
index 5f120de63..1955a3e66 100644
--- a/trie/encoding.go
+++ b/trie/encoding.go
@@ -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 {
diff --git a/trie/trie_test.go b/trie/trie_test.go
index f9d6029c9..4d84aa96c 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -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)
+ }
+}