rpc: fix limitedBuffer.Write to properly enforce size limit (#33545)

Updated the `avail` calculation to correctly compute remaining capacity:
`buf.limit - len(buf.output)`, ensuring the buffer never exceeds its
configured limit regardless of how many times `Write()` is called.
This commit is contained in:
Maxim Evtush 2026-01-13 14:25:53 +02:00 committed by GitHub
parent 1278b4891d
commit 5a1990d1d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -612,8 +612,11 @@ type limitedBuffer struct {
}
func (buf *limitedBuffer) Write(data []byte) (int, error) {
avail := max(buf.limit, len(buf.output))
if len(data) < avail {
avail := buf.limit - len(buf.output)
if avail <= 0 {
return 0, errTruncatedOutput
}
if len(data) <= avail {
buf.output = append(buf.output, data...)
return len(data), nil
}