Skip to content

Commit a4b51d1

Browse files
committed
Fix panic in metadata content writer on copy error
The `createAndCopy` function is only called when `nw.w` is nil in order to create a new writer and prepare it. The current code is attempting to close `nw.w` when there is a copy error. The correct behavior would be to close the new writer and not touch `nw.w`. Signed-off-by: Derek McGowan <[email protected]> (cherry picked from commit b9cf0d7) Signed-off-by: Derek McGowan <[email protected]>
1 parent 4de759a commit a4b51d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

metadata/content.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,13 @@ func (nw *namespacedWriter) createAndCopy(ctx context.Context, desc ocispec.Desc
551551
if desc.Size > 0 {
552552
ra, err := nw.provider.ReaderAt(ctx, nw.desc)
553553
if err != nil {
554+
w.Close()
554555
return err
555556
}
556557
defer ra.Close()
557558

558559
if err := content.CopyReaderAt(w, ra, desc.Size); err != nil {
559-
nw.w.Close()
560-
nw.w = nil
560+
w.Close()
561561
return err
562562
}
563563
}

0 commit comments

Comments
 (0)