From f8c702bd35e55d038848d9647bacb5c7585ee22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Fri, 28 Feb 2025 20:02:10 +0100 Subject: [PATCH] Rename copyImageBlobToFile to copyTrustedImageBlobToFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... and add a warning. Signed-off-by: Miloslav Trmač --- pkg/libartifact/store/store.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/libartifact/store/store.go b/pkg/libartifact/store/store.go index ca6fbc8a3b..7514943a58 100644 --- a/pkg/libartifact/store/store.go +++ b/pkg/libartifact/store/store.go @@ -371,7 +371,7 @@ func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target digest = arty.Manifest.Layers[0].Digest } - return copyImageBlobToFile(ctx, imgSrc, digest, target) + return copyTrustedImageBlobToFile(ctx, imgSrc, digest, target) } if len(options.Digest) > 0 || len(options.Title) > 0 { @@ -387,7 +387,7 @@ func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target if err != nil { return err } - return copyImageBlobToFile(ctx, imgSrc, digest, filepath.Join(target, filename)) + return copyTrustedImageBlobToFile(ctx, imgSrc, digest, filepath.Join(target, filename)) } for _, l := range arty.Manifest.Layers { @@ -396,7 +396,7 @@ func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target if err != nil { return err } - err = copyImageBlobToFile(ctx, imgSrc, l.Digest, filepath.Join(target, filename)) + err = copyTrustedImageBlobToFile(ctx, imgSrc, l.Digest, filepath.Join(target, filename)) if err != nil { return err } @@ -454,7 +454,11 @@ func findDigest(arty *libartifact.Artifact, options *libartTypes.ExtractOptions) return digest, nil } -func copyImageBlobToFile(ctx context.Context, imgSrc types.ImageSource, digest digest.Digest, target string) error { +// copyTrustedImageBlobToFile copies blob identified by digest in imgSrc to file target. +// +// WARNING: This does not validate the contents against the expected digest, so it should only +// be used to read from trusted sources! +func copyTrustedImageBlobToFile(ctx context.Context, imgSrc types.ImageSource, digest digest.Digest, target string) error { src, _, err := imgSrc.GetBlob(ctx, types.BlobInfo{Digest: digest}, nil) if err != nil { return fmt.Errorf("failed to get artifact file: %w", err)