From e4aaacc2351d2e1dd4b69afeeee2aeab9c625efe Mon Sep 17 00:00:00 2001
From: "Guillaume J. Charmes" <guillaume@charmes.net>
Date: Mon, 31 Mar 2014 10:49:48 -0700
Subject: [PATCH] Fix expending buffer in StdCopy

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
---
 utils/stdcopy.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/utils/stdcopy.go b/utils/stdcopy.go
index 3cb8ab02b3..8b43386140 100644
--- a/utils/stdcopy.go
+++ b/utils/stdcopy.go
@@ -108,12 +108,13 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error)
 
 		// Retrieve the size of the frame
 		frameSize = int(binary.BigEndian.Uint32(buf[StdWriterSizeIndex : StdWriterSizeIndex+4]))
+		Debugf("framesize: %d", frameSize)
 
 		// Check if the buffer is big enough to read the frame.
 		// Extend it if necessary.
 		if frameSize+StdWriterPrefixLen > bufLen {
-			Debugf("Extending buffer cap.")
-			buf = append(buf, make([]byte, frameSize-len(buf)+1)...)
+			Debugf("Extending buffer cap by %d (was %d)", frameSize+StdWriterPrefixLen-bufLen+1, len(buf))
+			buf = append(buf, make([]byte, frameSize+StdWriterPrefixLen-bufLen+1)...)
 			bufLen = len(buf)
 		}