Skip to content

Commit

Permalink
fix(storage): fix Writer.ChunkSize validation (#4255)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tritone committed Jun 14, 2021
1 parent f9db3e9 commit 69c2e9d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions storage/writer.go
Expand Up @@ -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),
}
Expand Down

0 comments on commit 69c2e9d

Please sign in to comment.