From 741230e54c59e0c03e99567f66648b7e97d234a1 Mon Sep 17 00:00:00 2001 From: Rafael Gieschke Date: Thu, 20 Dec 2018 16:47:33 +0100 Subject: [PATCH] Fix descriptor matching logic This fixes commit dab5ba5a642250dd8c2ddf954f9ffe60837a2e7b. The `for i := 0; i < len(descs); i++` loops inside findDescriptor skip one entry of descs at each non-match because the array length is reduced by 1 but the index i is not reduced: ``` skopeo copy docker://ubuntu oci:dir:a skopeo copy docker://ubuntu oci:dir:b skopeo copy docker://ubuntu oci:dir:c ./oci-image-tool unpack --ref name=c dir dir2 index.json: descriptor retrieved by refs [name=c] is not unique ``` Signed-off-by: Rafael Gieschke --- image/descriptor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/image/descriptor.go b/image/descriptor.go index 5bf19ac..318051b 100644 --- a/image/descriptor.go +++ b/image/descriptor.go @@ -72,18 +72,21 @@ func findDescriptor(w walker, names []string) ([]v1.Descriptor, error) { for i := 0; i < len(descs); i++ { if descs[i].Annotations[v1.AnnotationRefName] != argsParts[1] { descs = append(descs[:i], descs[i+1:]...) + i-- } } case "platform.os": for i := 0; i < len(descs); i++ { if descs[i].Platform != nil && index.Manifests[i].Platform.OS != argsParts[1] { descs = append(descs[:i], descs[i+1:]...) + i-- } } case "digest": for i := 0; i < len(descs); i++ { if string(descs[i].Digest) != argsParts[1] { descs = append(descs[:i], descs[i+1:]...) + i-- } } default: