Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 14935fb

Browse files
author
zhouhao
committed
add config validate
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent b88fd0b commit 14935fb

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

image/config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package image
1616

1717
import (
18+
"crypto/sha256"
19+
"encoding/hex"
1820
"bytes"
1921
"encoding/json"
2022
"fmt"
@@ -64,19 +66,23 @@ func findConfig(w walker, d *descriptor) (*config, error) {
6466
}
6567
}
6668

67-
func (c *config) validate(w walk) error {
69+
func (c *config) validate(w walker) error {
6870

6971
// check if the rootfs type is 'layers'
7072
if c.RootFS.Type != "layers" {
71-
return errors.New("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
73+
return errors.New("RootFs is an unknown rootfs type, MUST be 'layers'")
7274
}
7375

74-
for _, d = range c.RootFs.DiffIDs {
76+
for _, d := range c.RootFS.DiffIDs {
7577
h := sha256.New()
7678
DiffIds := "sha256" + hex.EncodeToString(h.Sum(nil))
7779

7880
if DiffIds != d {
7981
return errors.New("DiffIDs mismatch")
82+
}
83+
}
84+
85+
return nil
8086
}
8187

8288
func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) {

image/image.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
8484
return err
8585
}
8686

87-
if err := m.validate(w); err != nil {
87+
if err = m.validate(w); err != nil {
8888
return err
8989
}
9090

@@ -190,6 +190,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error {
190190
return err
191191
}
192192

193+
if err = c.validate(w); err != nil {
194+
return err
195+
}
196+
193197
err = m.unpack(w, filepath.Join(dest, rootfs))
194198
if err != nil {
195199
return err

0 commit comments

Comments
 (0)