Skip to content

Commit 654f854

Browse files
committed
reject null manifests
Signed-off-by: Josh Chorlton <jchorlton@gmail.com>
1 parent 8891c58 commit 654f854

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

daemon/images/image_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (i *ImageService) ExportImage(names []string, outStream io.Writer) error {
1717
}
1818

1919
// LoadImage uploads a set of images into the repository. This is the
20-
// complement of ImageExport. The input stream is an uncompressed tar
20+
// complement of ExportImage. The input stream is an uncompressed tar
2121
// ball containing images and metadata.
2222
func (i *ImageService) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
2323
imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStores, i.referenceStore, i)

image/tarexport/load.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
6363
return err
6464
}
6565

66+
if err := validateManifest(manifest); err != nil {
67+
return err
68+
}
69+
6670
var parentLinks []parentLink
6771
var imageIDsStr string
6872
var imageRefCount int
@@ -430,3 +434,13 @@ func checkCompatibleOS(imageOS string) error {
430434

431435
return system.ValidatePlatform(p)
432436
}
437+
438+
func validateManifest(manifest []manifestItem) error {
439+
// a nil manifest usually indicates a bug, so don't just silently fail.
440+
// if someone really needs to pass an empty manifest, they can pass [].
441+
if manifest == nil {
442+
return errors.New("invalid manifest, manifest cannot be null (but can be [])")
443+
}
444+
445+
return nil
446+
}

image/tarexport/load_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tarexport
2+
3+
import (
4+
"testing"
5+
6+
"gotest.tools/v3/assert"
7+
is "gotest.tools/v3/assert/cmp"
8+
)
9+
10+
func TestValidateManifest(t *testing.T) {
11+
cases := map[string]struct {
12+
manifest []manifestItem
13+
valid bool
14+
errContains string
15+
}{
16+
"nil": {
17+
manifest: nil,
18+
valid: false,
19+
errContains: "manifest cannot be null",
20+
},
21+
"non-nil": {
22+
manifest: []manifestItem{},
23+
valid: true,
24+
},
25+
}
26+
27+
for name, tc := range cases {
28+
t.Run(name, func(t *testing.T) {
29+
err := validateManifest(tc.manifest)
30+
if tc.valid {
31+
assert.Check(t, is.Nil(err))
32+
} else {
33+
assert.Check(t, is.ErrorContains(err, tc.errContains))
34+
}
35+
})
36+
}
37+
}

0 commit comments

Comments
 (0)