From 4ea45f1e18dc84c96d734c286da312be9eaf841b Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Mon, 14 Jun 2021 00:02:24 -0400 Subject: [PATCH] fix(storage): fix Writer.ChunkSize validation Since w.opened is set to true before this validation currently, subsequent calls to Writer.Close will deadlock. There is no reason not to do this check first before opening the pipe. Thanks to @dt for pointing this out. Updates #4167 --- storage/writer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/storage/writer.go b/storage/writer.go index 1843a814155..345f8bdb4c9 100644 --- a/storage/writer.go +++ b/storage/writer.go @@ -99,15 +99,15 @@ func (w *Writer) open() error { if attrs.KMSKeyName != "" && w.o.encryptionKey != nil { return errors.New("storage: cannot use KMSKeyName with a customer-supplied encryption key") } + if w.ChunkSize < 0 { + return errors.New("storage: Writer.ChunkSize must be non-negative") + } pr, pw := io.Pipe() w.pw = pw w.opened = true go w.monitorCancel() - if w.ChunkSize < 0 { - return errors.New("storage: Writer.ChunkSize must be non-negative") - } mediaOpts := []googleapi.MediaOption{ googleapi.ChunkSize(w.ChunkSize), }