Skip to content

Commit b9cf0d7

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]>
1 parent d0bedc5 commit b9cf0d7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

metadata/content.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,13 @@ func (nw *namespacedWriter) createAndCopy(ctx context.Context, desc ocispec.Desc
558558
if desc.Size > 0 {
559559
ra, err := nw.provider.ReaderAt(ctx, nw.desc)
560560
if err != nil {
561+
w.Close()
561562
return err
562563
}
563564
defer ra.Close()
564565

565566
if err := content.CopyReaderAt(w, ra, desc.Size); err != nil {
566-
nw.w.Close()
567-
nw.w = nil
567+
w.Close()
568568
return err
569569
}
570570
}

0 commit comments

Comments
 (0)