{"record":{"id":"342d947f91412ec4","repo":"hyperledger/fabric","slug":"invalid-file-type-v-contained-in-archive-for-fi","errorCode":null,"errorMessage":"invalid file type '%v' contained in archive for file '%s'","messagePattern":"invalid file type '(.+?)' contained in archive for file '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/container/externalbuilder/tar.go","lineNumber":71,"sourceCode":"\t\t\t}\n\t\tcase tar.TypeReg:\n\t\t\tif err := os.MkdirAll(filepath.Dir(target), 0o700); err != nil {\n\t\t\t\treturn errors.WithMessagef(err, \"could not create directory '%s'\", filepath.Dir(header.Name))\n\t\t\t}\n\n\t\t\tf, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))\n\t\t\tif err != nil {\n\t\t\t\treturn errors.WithMessagef(err, \"could not create file '%s'\", header.Name)\n\t\t\t}\n\n\t\t\t// copy over contents\n\t\t\tif _, err := io.Copy(f, tr); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tf.Close()\n\t\tdefault:\n\t\t\treturn errors.Errorf(\"invalid file type '%v' contained in archive for file '%s'\", header.Typeflag, header.Name)\n\t\t}\n\t}\n}\n\n// ValidPath checks to see if the path is absolute, or if it is a\n// relative path higher in the tree.  In these cases it returns false.\nfunc ValidPath(uncleanPath string) bool {\n\t// sanitizedPath will eliminate non-prefix instances of '..', as well\n\t// as strip './'\n\tsanitizedPath := filepath.Clean(uncleanPath)\n\n\tswitch {\n\tcase filepath.IsAbs(sanitizedPath):\n\t\treturn false\n\tcase strings.HasPrefix(sanitizedPath, \"..\"+string(filepath.Separator)) || sanitizedPath == \"..\":\n\t\t// Path refers either to the parent, or a directory relative to the parent (but allows ..foo or ... for instance)\n\t\treturn false\n\tdefault:","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/container/externalbuilder/tar.go#L53-L89","documentation":"Untar only supports regular files and directories; any other tar entry type (symlinks, hardlinks, devices, FIFOs, etc.) hits the default case and returns this error naming the typeflag and entry. It prevents unexpected/special file types from entering the build context.","triggerScenarios":"Archiving a directory tree that contains symbolic links, hard links, sockets, FIFOs, or device nodes (e.g. GNU tar capturing node_modules symlinks) and feeding it to Untar.","commonSituations":"Packaging symlink-heavy trees (node_modules, venv) on Linux/macOS; tars generated with 'tar -cf' over directories containing /dev entries or sockets; build tool caches that include links.","solutions":["Dereference links when archiving: use 'tar -ch' (--dereference) so entries are stored as regular files.","Exclude special files from the archive (tar --exclude patterns for symlinks, sockets, pipes).","Pre-process the source tree to remove or resolve symlinks before packaging.","If links are genuinely required, modify the packager to represent them differently and extend Untar's supported typeflags."],"exampleFix":"// before\ntar -cf pkg.tar ./output   // output contains symlinks\n// after\ntar -chf pkg.tar ./output  // dereference links into regular files","handlingStrategy":"validation","validationCode":"hdrs, err := tarHeaderTypes(pkgPath)\nif err != nil { return err }\nfor name, tf := range hdrs {\n    if tf != tar.TypeReg && tf != tar.TypeDir {\n        return fmt.Errorf(\"unsupported type %v for %s\", tf, name)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := externalbuilder.Untar(dst, r); err != nil {\n    if strings.Contains(err.Error(), \"invalid file type\") {\n        return fmt.Errorf(\"repackage archive without links/special files: %w\", err)\n    }\n    return err\n}","preventionTips":["Use tar -h/--dereference when packaging symlink-heavy trees.","Exclude sockets, FIFOs and device nodes from archives.","Inspect archives with 'tar -tvf' before packaging for delivery.","Keep packagers and Untar's supported typeflags in sync."],"tags":["tar","archive","validation"],"backgroundTag":"unsupported-file-type-in-archive","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}