Skip to content

Commit

Permalink
make image parent check more robust
Browse files Browse the repository at this point in the history
Follow up on issue #7444 and make the parent checks more robust.
We can end up with an incoherent storage when, for instance, a
build has been killed.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Sep 7, 2020
1 parent ba8d0bb commit 238abf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,11 +1247,14 @@ func areParentAndChild(parent, child *imgspecv1.Image) bool {
// candidate parent's diff IDs, which together would have
// controlled which layers were used

// issue #7444 describes a panic where the length of child.RootFS.DiffIDs
// is checked but child is nil. Adding a simple band-aid approach to prevent
// the problem until the origin of the problem can be worked out in the issue
// itself.
if child == nil || len(parent.RootFS.DiffIDs) > len(child.RootFS.DiffIDs) {
// Both, child and parent, may be nil when the storage is left in an
// incoherent state. Issue #7444 describes such a case when a build
// has been killed.
if child == nil || parent == nil {
return false
}

if len(parent.RootFS.DiffIDs) > len(child.RootFS.DiffIDs) {
return false
}
childUsesCandidateDiffs := true
Expand Down
4 changes: 3 additions & 1 deletion libpod/image/layer_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (t *layerTree) toOCI(ctx context.Context, i *Image) (*ociv1.Image, error) {
oci, exists := t.ociCache[i.ID()]
if !exists {
oci, err = i.ociv1Image(ctx)
t.ociCache[i.ID()] = oci
if err == nil {
t.ociCache[i.ID()] = oci
}
}
return oci, err
}
Expand Down

0 comments on commit 238abf6

Please sign in to comment.