diff --git a/fastnode/fast_node.go b/fastnode/fast_node.go index 149ac9b26..5d00bd997 100644 --- a/fastnode/fast_node.go +++ b/fastnode/fast_node.go @@ -30,6 +30,7 @@ func NewNode(key []byte, value []byte, version int64) *Node { } // DeserializeNode constructs an *FastNode from an encoded byte slice. +// It assumes we do not mutate this input []byte. func DeserializeNode(key []byte, buf []byte) (*Node, error) { ver, n, err := encoding.DecodeVarint(buf) if err != nil { diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go index 17a994bc1..40d558da3 100644 --- a/internal/encoding/encoding.go +++ b/internal/encoding/encoding.go @@ -30,6 +30,7 @@ var uvarintPool = &sync.Pool{ // decodeBytes decodes a varint length-prefixed byte slice, returning it along with the number // of input bytes read. +// Assumes bz will not be mutated. func DecodeBytes(bz []byte) ([]byte, int, error) { s, n, err := DecodeUvarint(bz) if err != nil { @@ -51,9 +52,7 @@ func DecodeBytes(bz []byte) ([]byte, int, error) { if len(bz) < end { return nil, n, fmt.Errorf("insufficient bytes decoding []byte of length %v", size) } - bz2 := make([]byte, size) - copy(bz2, bz[n:end]) - return bz2, end, nil + return bz[n:end], end, nil } // decodeUvarint decodes a varint-encoded unsigned integer from a byte slice, returning it and the