Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes detection if the image contains compressed layers #1981

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions pkg/v1/tarball/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Image(opener Opener, tag *name.Tag) (v1.Image, error) {
return nil, err
}

// Peek at the first layer and see if it's compressed.
// Check all layers and see if there is any compressed layer
if len(img.imgDescriptor.Layers) > 0 {
compressed, err := img.areLayersCompressed()
if err != nil {
Expand Down Expand Up @@ -160,19 +160,26 @@ func (i *image) areLayersCompressed() (bool, error) {
if len(i.imgDescriptor.Layers) == 0 {
return false, errors.New("0 layers found in image")
}
layer := i.imgDescriptor.Layers[0]
blob, err := extractFileFromTar(i.opener, layer)
if err != nil {
return false, err
}
defer blob.Close()

cp, _, err := comp.PeekCompression(blob)
if err != nil {
return false, err
// base image could be uncompressed while the top layers are compressed
for _, layer := range i.imgDescriptor.Layers {
blob, err := extractFileFromTar(i.opener, layer)
if err != nil {
return false, err
}
defer blob.Close()

cp, _, err := comp.PeekCompression(blob)
if err != nil {
return false, err
}

if cp != compression.None {
return true, nil
}
}

return cp != compression.None, nil
return false, nil
}

func (i *image) loadTarDescriptorAndConfig() error {
Expand Down
Loading