From af59e95a104195014f05de06e72a0c01dfdae054 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 17 Jan 2017 11:29:24 -0400 Subject: [PATCH] ensure copy of p when Writing stays within bounds --- sync.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sync.go b/sync.go index 509e7c9..4952940 100644 --- a/sync.go +++ b/sync.go @@ -131,8 +131,14 @@ func (w *PipeWriter) Write(p []byte) (n int, err error) { w.c.Wait() } - // chunk write to fill space - m, err = w.b.Write(p[n : int64(n)+gap(w.b)]) + // now that we have the lock, see what the real gap is + nn := int64(n) + gap(w.b) + if nn > int64(len(p)) { + // it's grown enough, just do a standard write + break + } + + m, err = w.b.Write(p[n:nn]) n += m if err != nil { return n, err