1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-12 14:10:32 +08:00

fix: decode out of range

This commit is contained in:
源文雨
2022-03-15 17:28:29 +08:00
parent d84411a4ef
commit 42e4c3cd4b

View File

@@ -26,7 +26,7 @@ func Encode(b []byte) (encd []byte) {
case 6: case 6:
outlen += 10 outlen += 10
} }
encd = make([]byte, outlen, outlen+8) //冗余的8B用于可能的结尾的覆盖 encd = make([]byte, outlen)
var n int var n int
i := 0 i := 0
for ; i <= len(b)-7; i += 7 { for ; i <= len(b)-7; i += 7 {
@@ -115,8 +115,9 @@ func Decode(b []byte) (decd []byte) {
i++ i++
} }
if offset > 0 { if offset > 0 {
b = append(b, make([]byte, offset)...) var tmp [8]byte
sum := binary.LittleEndian.Uint64(b[n:]) - 0x000000000000004e copy(tmp[:], b[n:])
sum := binary.LittleEndian.Uint64(tmp[:]) - 0x000000000000004e
decd[i] = byte(((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14)) decd[i] = byte(((sum & 0x000000000000003f) << 2) | ((sum & 0x000000000000c000) >> 14))
i++ i++
if offset > 1 { if offset > 1 {