Skip to content

Commit 83edaef

Browse files
committed
exporter: validate null config metadata from gateway
Signed-off-by: Tonis Tiigi <[email protected]> (cherry picked from commit ef536af15b2d351b8f0459022decc2a4955b1cb2) (cherry picked from commit a8a6bc5180696624b18b5dc4ed4f9cf1a278ef27)
1 parent 369b850 commit 83edaef

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

client/client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func TestIntegration(t *testing.T) {
206206
testMultipleRecordsWithSameLayersCacheImportExport,
207207
testExportLocalNoPlatformSplit,
208208
testExportLocalNoPlatformSplitOverwrite,
209+
testValidateNullConfig,
209210
)
210211
}
211212

client/validation_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"io"
6+
"testing"
7+
8+
"github.com/moby/buildkit/client/llb"
9+
"github.com/moby/buildkit/frontend/gateway/client"
10+
"github.com/moby/buildkit/util/testutil/integration"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func testValidateNullConfig(t *testing.T, sb integration.Sandbox) {
15+
requiresLinux(t)
16+
17+
ctx := sb.Context()
18+
19+
c, err := New(ctx, sb.Address())
20+
require.NoError(t, err)
21+
defer c.Close()
22+
23+
b := func(ctx context.Context, c client.Client) (*client.Result, error) {
24+
def, err := llb.Scratch().Marshal(ctx)
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
res, err := c.Solve(ctx, client.SolveRequest{
30+
Evaluate: true,
31+
Definition: def.ToPB(),
32+
})
33+
if err != nil {
34+
return nil, err
35+
}
36+
res.AddMeta("containerimage.config", []byte("null"))
37+
return res, nil
38+
}
39+
40+
_, err = c.Build(ctx, SolveOpt{
41+
Exports: []ExportEntry{
42+
{
43+
Type: ExporterOCI,
44+
Output: fixedWriteCloser(nopWriteCloser{io.Discard}),
45+
},
46+
},
47+
}, "", b, nil)
48+
require.Error(t, err)
49+
require.Contains(t, err.Error(), "invalid null image config for export")
50+
}

exporter/containerimage/writer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,20 @@ func parseHistoryFromConfig(dt []byte) ([]ocispecs.History, error) {
569569
}
570570

571571
func patchImageConfig(dt []byte, descs []ocispecs.Descriptor, history []ocispecs.History, cache []byte, epoch *time.Time) ([]byte, error) {
572+
var img ocispecs.Image
573+
if err := json.Unmarshal(dt, &img); err != nil {
574+
return nil, errors.Wrap(err, "invalid image config for export")
575+
}
576+
572577
m := map[string]json.RawMessage{}
573578
if err := json.Unmarshal(dt, &m); err != nil {
574579
return nil, errors.Wrap(err, "failed to parse image config for patch")
575580
}
576581

582+
if m == nil {
583+
return nil, errors.Errorf("invalid null image config for export")
584+
}
585+
577586
var rootFS ocispecs.RootFS
578587
rootFS.Type = "layers"
579588
for _, desc := range descs {

0 commit comments

Comments
 (0)