From 8abb44f2180ae32ed504e761ea6f4646a75a63ab Mon Sep 17 00:00:00 2001 From: Lehel Gyuro Date: Tue, 27 Oct 2020 22:10:33 +0100 Subject: [PATCH 1/2] [#7696] Avoid crash in chart loader on unexpected file sequence Make sure, that chart metadata is initialized by the time the processing of the chart is started. Signed-off-by: Lehel Gyuro --- pkg/chart/loader/load.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index c9d57234e..84aaa44df 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -73,10 +73,11 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { c := new(chart.Chart) subcharts := make(map[string][]*BufferedFile) + // do not rely on assumed ordering of files in the chart and crash + // if Chart.yaml was not coming early enough to initialize metadata for _, f := range files { c.Raw = append(c.Raw, &chart.File{Name: f.Name, Data: f.Data}) - switch { - case f.Name == "Chart.yaml": + if f.Name == "Chart.yaml" { if c.Metadata == nil { c.Metadata = new(chart.Metadata) } @@ -89,6 +90,14 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { if c.Metadata.APIVersion == "" { c.Metadata.APIVersion = chart.APIVersionV1 } + } + } + for _, f := range files { + c.Raw = append(c.Raw, &chart.File{Name: f.Name, Data: f.Data}) + switch { + case f.Name == "Chart.yaml": + // already processed + continue case f.Name == "Chart.lock": c.Lock = new(chart.Lock) if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil { From 27807e1bb5f37248c59b26e6ac2e4e47bfe5fe9f Mon Sep 17 00:00:00 2001 From: Lehel Gyuro Date: Tue, 27 Oct 2020 22:10:33 +0100 Subject: [PATCH 2/2] [#7696] Avoid crash in chart loader on unexpected file sequence Make sure, that chart metadata is initialized by the time the processing of the chart is started. Signed-off-by: Lehel Gyuro --- pkg/chart/loader/load.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index 84aaa44df..90c0b38ae 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -93,7 +93,6 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { } } for _, f := range files { - c.Raw = append(c.Raw, &chart.File{Name: f.Name, Data: f.Data}) switch { case f.Name == "Chart.yaml": // already processed