Skip to content
Permalink
Browse files
fix: context extraction error
Context extraction error may occur when an archive contains file node without parent directory node.

Fixes #4260.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Mar 21, 2022
1 parent 69e1bb0 commit d19cfb6f6f60f4ca5ea952cd794c5ac9d439dbaf
Showing with 4 additions and 0 deletions.
  1. +4 −0 pkg/util/archive.go
@@ -192,6 +192,10 @@ func ExtractTar(tarFileReader io.Reader, dstDir string) error {
return fmt.Errorf("unable to create new dir %q while extracting tar: %s", tarEntryPath, err)
}
case tar.TypeReg, tar.TypeSymlink, tar.TypeLink, tar.TypeGNULongName, tar.TypeGNULongLink:
if err := os.MkdirAll(filepath.Dir(tarEntryPath), os.ModePerm); err != nil {
return fmt.Errorf("unable to create new directory %q while extracting tar: %w", filepath.Dir(tarEntryPath), err)
}

file, err := os.OpenFile(tarEntryPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, tarEntryFileInfo.Mode())
if err != nil {
return fmt.Errorf("unable to create new file %q while extracting tar: %s", tarEntryPath, err)

0 comments on commit d19cfb6

Please sign in to comment.