Fix possible runtime panic if image history len is zero

We now return an empty string for the `Comment` field if an OCI v1 image
contains no history.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
Sascha Grunert
2019-07-25 12:45:08 +02:00
parent 7c9095ea1d
commit 7630f1b52e

View File

@@ -1298,7 +1298,10 @@ func (i *Image) Comment(ctx context.Context, manifestType string) (string, error
if err != nil {
return "", err
}
return ociv1Img.History[0].Comment, nil
if len(ociv1Img.History) > 0 {
return ociv1Img.History[0].Comment, nil
}
return "", nil
}
// Save writes a container image to the filesystem