From 46040a71c3670899c6af65b627d0a4f8e8c390f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 19 Mar 2023 10:25:26 +0800 Subject: [PATCH] Fix vision padding overflow --- transport/vless/vision.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/transport/vless/vision.go b/transport/vless/vision.go index 81ae58ef..7dc78cc9 100644 --- a/transport/vless/vision.go +++ b/transport/vless/vision.go @@ -286,14 +286,23 @@ func (c *VisionConn) padding(buffer *buf.Buffer, command byte) *buf.Buffer { l, _ := rand.Int(rand.Reader, big.NewInt(256)) paddingLen = int(l.Int64()) } - newBuffer := buf.New() + var bufferLen int if c.writeUUID { - newBuffer.Write(c.userUUID[:]) + bufferLen += 16 + } + bufferLen += 5 + if buffer != nil { + bufferLen += buffer.Len() + } + bufferLen += paddingLen + newBuffer := buf.NewSize(bufferLen) + if c.writeUUID { + common.Must1(newBuffer.Write(c.userUUID[:])) c.writeUUID = false } - newBuffer.Write([]byte{command, byte(contentLen >> 8), byte(contentLen), byte(paddingLen >> 8), byte(paddingLen)}) + common.Must1(newBuffer.Write([]byte{command, byte(contentLen >> 8), byte(contentLen), byte(paddingLen >> 8), byte(paddingLen)})) if buffer != nil { - newBuffer.Write(buffer.Bytes()) + common.Must1(newBuffer.Write(buffer.Bytes())) buffer.Release() } newBuffer.Extend(paddingLen)