Skip to content

Commit

Permalink
fix(image): parse image.inspect.Created field only for non-empty va…
Browse files Browse the repository at this point in the history
…lues (#6948)
  • Loading branch information
DmitriyLewen authored Jun 19, 2024
1 parent c3192f0 commit 0af5730
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/fanal/image/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,25 @@ func (img *image) ConfigFile() (*v1.ConfigFile, error) {
return nil, xerrors.Errorf("unable to get diff IDs: %w", err)
}

created, err := time.Parse(time.RFC3339Nano, img.inspect.Created)
if err != nil {
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
var created v1.Time
// `Created` field can be empty. Skip parsing to avoid error.
// cf. https://github.com/moby/moby/blob/8e96db1c328d0467b015768e42a62c0f834970bb/api/types/types.go#L76-L77
if img.inspect.Created != "" {
var t time.Time
t, err = time.Parse(time.RFC3339Nano, img.inspect.Created)
if err != nil {
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
}
created = v1.Time{
Time: t,
}
}

return &v1.ConfigFile{
Architecture: img.inspect.Architecture,
Author: img.inspect.Author,
Container: img.inspect.Container,
Created: v1.Time{Time: created},
Created: created,
DockerVersion: img.inspect.DockerVersion,
Config: img.imageConfig(img.inspect.Config),
History: img.history,
Expand Down

0 comments on commit 0af5730

Please sign in to comment.