Skip to content

Commit

Permalink
libimage/layer_tree: if parent is empty and manifest list ignore
Browse files Browse the repository at this point in the history
Layer tree expectes to form a relation between child and parent
instances, however it expects an instance from manifest list which is
empty, following expectation is not possible and will always resuilt in
error.

Closes: containers/podman#19860

[NO NEW TESTS NEEDED]
Image without layer cant be built in libimage, and `podman save`
automatically malforms such image so no such external image can be
loaded.

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Sep 14, 2023
1 parent d2b4327 commit 6365dad
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libimage/layer_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) {
if childID == empty.ID() {
continue
}
isManifest, err := empty.IsManifestList(ctx)
if err != nil {
return nil, err
}
if isManifest {
// If this is a manifest list and is already
// marked as empty then no instance can be
continue
}
emptyOCI, err := t.toOCI(ctx, empty)
if err != nil {
if ErrorIsImageUnknown(err) {
Expand Down
54 changes: 54 additions & 0 deletions libimage/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package libimage

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestListWithEmptyLayerImage(t *testing.T) {
runtime, cleanup := testNewRuntime(t)
defer cleanup()
ctx := context.Background()
loadOptions := &LoadOptions{}
loadOptions.Writer = os.Stdout

list, err := runtime.CreateManifestList("m")
require.NoError(t, err)
require.NotNil(t, list)

for _, test := range []struct {
input string
expectError bool
numImages int
names []string
}{
// OCI ARCHIVE
{"testdata/empty_image.tar", false, 1, []string{"localhost/i:latest"}},
} {
loadedImages, err := runtime.Load(ctx, test.input, loadOptions)
if test.expectError {
require.Error(t, err, test.input)
continue
}
require.NoError(t, err, test.input)
require.Equal(t, test.names, loadedImages, test.input)

// Make sure that all returned names exist as images in the
// local containers storage.
ids := []string{} // later used for image removal
names := [][]string{}
for _, name := range loadedImages {
image, resolvedName, err := runtime.LookupImage(name, nil)
require.NoError(t, err, test.input)
require.Equal(t, name, resolvedName, test.input)
ids = append(ids, image.ID())
names = append(names, image.Names())
}
}
listedImages, err := runtime.ListImages(ctx, nil, &ListImagesOptions{})
require.NoError(t, err)
require.Len(t, listedImages, 2, "expected 2 images")
}
Binary file added libimage/testdata/empty_image.tar
Binary file not shown.

0 comments on commit 6365dad

Please sign in to comment.