From 5a1990d1d8b30168c427fc76468dd482a90957eb Mon Sep 17 00:00:00 2001 From: Maxim Evtush <154841002+maximevtush@users.noreply.github.com> Date: Tue, 13 Jan 2026 14:25:53 +0200 Subject: [PATCH] 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. --- rpc/handler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rpc/handler.go b/rpc/handler.go index 45558d5821..462519d872 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -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 }