Fix vision padding overflow

This commit is contained in:
世界 2023-03-19 10:25:26 +08:00
parent 0558b3fc5c
commit 46040a71c3
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -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)