credentials/alts: Add comments to clarify buffer sizing (#8232)

This commit is contained in:
Arjan Singh Bal 2025-04-08 09:03:28 +05:30 committed by GitHub
parent db81a2cb4f
commit be25d96c52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -166,7 +166,12 @@ func (p *conn) Read(b []byte) (n int, err error) {
panic(fmt.Sprintf("protected buffer length shorter than expected: %d vs %d", len(p.protected), MsgLenFieldSize))
}
oldProtectedBuf := p.protected
p.protected = make([]byte, int(length)+MsgLenFieldSize)
// The new buffer must be able to hold the message length header
// and the entire message.
requiredCapacity := int(length) + MsgLenFieldSize
p.protected = make([]byte, requiredCapacity)
// Copy the contents of the old buffer and set the length of the
// new buffer to the number of bytes already read.
copy(p.protected, oldProtectedBuf)
p.protected = p.protected[:len(oldProtectedBuf)]
}