Skip to content

Commit

Permalink
Fix panic in metadata content writer on copy error
Browse files Browse the repository at this point in the history
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 <derek@mcg.dev>
  • Loading branch information
dmcgowan committed Sep 23, 2021
1 parent d0bedc5 commit b9cf0d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metadata/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,13 @@ func (nw *namespacedWriter) createAndCopy(ctx context.Context, desc ocispec.Desc
if desc.Size > 0 {
ra, err := nw.provider.ReaderAt(ctx, nw.desc)
if err != nil {
w.Close()
return err
}
defer ra.Close()

if err := content.CopyReaderAt(w, ra, desc.Size); err != nil {
nw.w.Close()
nw.w = nil
w.Close()
return err
}
}
Expand Down

0 comments on commit b9cf0d7

Please sign in to comment.