mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
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. Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com>
This commit is contained in:
parent
03da570aca
commit
0c306686bb
1 changed files with 5 additions and 2 deletions
|
|
@ -612,8 +612,11 @@ type limitedBuffer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buf *limitedBuffer) Write(data []byte) (int, error) {
|
func (buf *limitedBuffer) Write(data []byte) (int, error) {
|
||||||
avail := max(buf.limit, len(buf.output))
|
avail := buf.limit - len(buf.output)
|
||||||
if len(data) < avail {
|
if avail <= 0 {
|
||||||
|
return 0, errTruncatedOutput
|
||||||
|
}
|
||||||
|
if len(data) <= avail {
|
||||||
buf.output = append(buf.output, data...)
|
buf.output = append(buf.output, data...)
|
||||||
return len(data), nil
|
return len(data), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue