From 42e4c3cd4b96761c8edfce06cc27b691f7f0c473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:28:29 +0800 Subject: [PATCH] fix: decode out of range --- base14.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/base14.go b/base14.go index 8b67f46..edb6921 100644 --- a/base14.go +++ b/base14.go @@ -26,7 +26,7 @@ func Encode(b []byte) (encd []byte) { case 6: outlen += 10 } - encd = make([]byte, outlen, outlen+8) //冗余的8B用于可能的结尾的覆盖 + encd = make([]byte, outlen) var n int i := 0 for ; i <= len(b)-7; i += 7 { @@ -115,8 +115,9 @@ func Decode(b []byte) (decd []byte) { i++ } if offset > 0 { - b = append(b, make([]byte, offset)...) - sum := binary.LittleEndian.Uint64(b[n:]) - 0x000000000000004e + var tmp [8]byte + copy(tmp[:], b[n:]) + sum := binary.LittleEndian.Uint64(tmp[:]) - 0x000000000000004e decd[i] = byte(((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14)) i++ if offset > 1 {