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

Commit c9d0009

Browse files
author
zhouhao
committed
autodetect.go:Increase the judgment criteria for the ImageLayout file type
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent 374a7f6 commit c9d0009

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

image/image.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ var validRefMediaTypes = []string{
4949
}
5050

5151
func validate(w walker, refs []string, out *log.Logger) error {
52+
if err := layoutValidate(w); err != nil {
53+
return err
54+
}
55+
5256
ds, err := listReferences(w)
5357
if err != nil {
5458
return err

image/layout.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package image
16+
17+
import (
18+
"fmt"
19+
"io"
20+
"os"
21+
"strings"
22+
)
23+
24+
var blobsFile, indexFile, layoutFile int
25+
26+
func layoutValidate(w walker) error {
27+
var err error
28+
err = w.walk(func(path string, info os.FileInfo, r io.Reader) error {
29+
if strings.EqualFold(path, "blobs") {
30+
blobsFile++
31+
return nil
32+
}
33+
34+
if strings.EqualFold(path, "index.json") {
35+
indexFile++
36+
return nil
37+
}
38+
39+
if strings.EqualFold(path, "oci-layout") {
40+
layoutFile++
41+
return nil
42+
}
43+
44+
return nil
45+
})
46+
47+
if err != nil {
48+
return err
49+
}
50+
51+
if err == nil {
52+
if blobsFile != 1 {
53+
return fmt.Errorf("image layout must contain blobs directory")
54+
}
55+
56+
if indexFile != 1 {
57+
return fmt.Errorf("image layout must contain index.json file")
58+
}
59+
60+
if layoutFile != 1 {
61+
return fmt.Errorf("image layout must contain an oci-layout file")
62+
}
63+
64+
return nil
65+
}
66+
67+
return nil
68+
}

0 commit comments

Comments
 (0)