Skip to content

Commit 8a638b7

Browse files
ctalledok8s-infra-cherrypick-robot
authored andcommitted
Prevent panic in Docker pusher.
Prevent a panic in the Docker pusher pushWriter, by checking that the pipe is non nil before attempting to use it. The panic was found by Moby issue #46746 (moby/moby#46746). With this fix the panic no longer reproduces. Signed-off-by: Cesar Talledo <[email protected]>
1 parent 9e97c2e commit 8a638b7

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

core/remotes/docker/pusher.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,15 @@ func (pw *pushWriter) Digest() digest.Digest {
477477

478478
func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
479479
// Check whether read has already thrown an error
480-
if _, err := pw.pipe.Write([]byte{}); err != nil && !errors.Is(err, io.ErrClosedPipe) {
481-
return fmt.Errorf("pipe error before commit: %w", err)
480+
if pw.pipe != nil {
481+
if _, err := pw.pipe.Write([]byte{}); err != nil && !errors.Is(err, io.ErrClosedPipe) {
482+
return fmt.Errorf("pipe error before commit: %w", err)
483+
}
484+
if err := pw.pipe.Close(); err != nil {
485+
return err
486+
}
482487
}
483488

484-
if err := pw.pipe.Close(); err != nil {
485-
return err
486-
}
487489
// TODO: timeout waiting for response
488490
var resp *http.Response
489491
select {

0 commit comments

Comments
 (0)