Skip to content

Commit 0af5730

Browse files
authored
fix(image): parse image.inspect.Created field only for non-empty values (#6948)
1 parent c3192f0 commit 0af5730

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/fanal/image/daemon/image.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,25 @@ func (img *image) ConfigFile() (*v1.ConfigFile, error) {
110110
return nil, xerrors.Errorf("unable to get diff IDs: %w", err)
111111
}
112112

113-
created, err := time.Parse(time.RFC3339Nano, img.inspect.Created)
114-
if err != nil {
115-
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
113+
var created v1.Time
114+
// `Created` field can be empty. Skip parsing to avoid error.
115+
// cf. https://github.com/moby/moby/blob/8e96db1c328d0467b015768e42a62c0f834970bb/api/types/types.go#L76-L77
116+
if img.inspect.Created != "" {
117+
var t time.Time
118+
t, err = time.Parse(time.RFC3339Nano, img.inspect.Created)
119+
if err != nil {
120+
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
121+
}
122+
created = v1.Time{
123+
Time: t,
124+
}
116125
}
117126

118127
return &v1.ConfigFile{
119128
Architecture: img.inspect.Architecture,
120129
Author: img.inspect.Author,
121130
Container: img.inspect.Container,
122-
Created: v1.Time{Time: created},
131+
Created: created,
123132
DockerVersion: img.inspect.DockerVersion,
124133
Config: img.imageConfig(img.inspect.Config),
125134
History: img.history,

0 commit comments

Comments
 (0)