Skip to content

Commit

Permalink
Fix helm may identify achieve of the application/x-gzip as applicatio…
Browse files Browse the repository at this point in the history
…n/vnd.ms-fontobject

Signed-off-by: MR ZHAO <62738635+heijian123@users.noreply.github.com>
  • Loading branch information
heijian123 committed Aug 7, 2023
1 parent 37cc2fa commit 5c7a631
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/chart/loader/archive.go
Expand Up @@ -85,7 +85,10 @@ func ensureArchive(name string, raw *os.File) error {
if err != nil && err != io.EOF {
return fmt.Errorf("file '%s' cannot be read: %s", name, err)
}
if contentType := http.DetectContentType(buffer); contentType != "application/x-gzip" {

// Helm may identify achieve of the application/x-gzip as application/vnd.ms-fontobject.
// Fix for: https://github.com/helm/helm/issues/12261
if contentType := http.DetectContentType(buffer); contentType != "application/x-gzip" && !isGZipApplication(buffer) {
// TODO: Is there a way to reliably test if a file content is YAML? ghodss/yaml accepts a wide
// variety of content (Makefile, .zshrc) as valid YAML without errors.

Expand All @@ -98,6 +101,12 @@ func ensureArchive(name string, raw *os.File) error {
return nil
}

// isGZipApplication checks whether the achieve is of the application/x-gzip type.
func isGZipApplication(data []byte) bool {
sig := []byte("\x1F\x8B\x08")
return bytes.HasPrefix(data, sig)
}

// LoadArchiveFiles reads in files out of an archive into memory. This function
// performs important path security checks and should always be used before
// expanding a tarball
Expand Down

0 comments on commit 5c7a631

Please sign in to comment.