From 81e43b87c2b9eb9a112e21aaaea04a202c4f4d55 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 10 Dec 2021 13:08:10 -0800 Subject: [PATCH] Don't zero buffer if big enough (#13877) Only append zeroed bytes when we don't have enough space anyway. --- cmd/xl-storage-format-v2.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/xl-storage-format-v2.go b/cmd/xl-storage-format-v2.go index 05a3255d9..fa0848f7d 100644 --- a/cmd/xl-storage-format-v2.go +++ b/cmd/xl-storage-format-v2.go @@ -658,7 +658,12 @@ func readXLMetaNoData(r io.Reader, size int64) ([]byte, error) { return io.ErrUnexpectedEOF } extra := n - has - buf = append(buf, make([]byte, extra)...) + if int64(cap(buf)) >= n { + // Extend since we have enough space. + buf = buf[:n] + } else { + buf = append(buf, make([]byte, extra)...) + } _, err := io.ReadFull(r, buf[has:]) if err != nil { if errors.Is(err, io.EOF) {