From 27516f32d62471fc5939e535a9b804e8fb5b7b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 May 2024 19:25:03 +0200 Subject: [PATCH] Don't modify a storage.Layer returned by c/storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This shouldn't matter in practice because the returned struct happens to be a copy, but that's not promised by the API. Should not change behavior. Signed-off-by: Miloslav Trmač --- storage/storage_src.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/storage_src.go b/storage/storage_src.go index 2971f7fe9..e4fc5b52c 100644 --- a/storage/storage_src.go +++ b/storage/storage_src.go @@ -307,9 +307,6 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige if err != nil { return nil, fmt.Errorf("reading layer %q in image %q: %w", layerID, s.image.ID, err) } - if layer.UncompressedSize < 0 { - layer.UncompressedSize = -1 - } blobDigest := layer.UncompressedDigest if blobDigest == "" { @@ -331,12 +328,16 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige return nil, fmt.Errorf("parsing expected diffID %q for layer %q: %w", expectedDigest, layerID, err) } } + size := layer.UncompressedSize + if size < 0 { + size = -1 + } s.getBlobMutex.Lock() s.getBlobMutexProtected.digestToLayerID[blobDigest] = layer.ID s.getBlobMutex.Unlock() blobInfo := types.BlobInfo{ Digest: blobDigest, - Size: layer.UncompressedSize, + Size: size, MediaType: uncompressedLayerType, } physicalBlobInfos = append([]types.BlobInfo{blobInfo}, physicalBlobInfos...)