{"record":{"id":"a5e1532ac45510e7","repo":"hyperledger/fabric","slug":"failed-calculating-fileinfoheader-s","errorCode":null,"errorMessage":"failed calculating FileInfoHeader: %s","messagePattern":"failed calculating FileInfoHeader: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/writer.go","lineNumber":122,"sourceCode":"}\n\n// WriteFileToPackage writes a file to a tar stream.\nfunc WriteFileToPackage(localpath string, packagepath string, tw *tar.Writer) error {\n\tlogger.Debug(\"Writing file to tarball:\", packagepath)\n\tfd, err := os.Open(localpath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %s\", localpath, err)\n\t}\n\tdefer fd.Close()\n\n\tfi, err := fd.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %s\", localpath, err)\n\t}\n\n\theader, err := tar.FileInfoHeader(fi, localpath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed calculating FileInfoHeader: %s\", err)\n\t}\n\n\t// Take the variance out of the tar by using zero time and fixed uid/gid.\n\tvar zeroTime time.Time\n\theader.AccessTime = zeroTime\n\theader.ModTime = zeroTime\n\theader.ChangeTime = zeroTime\n\theader.Name = packagepath\n\theader.Mode = 0o100644\n\theader.Uid = 500\n\theader.Gid = 500\n\theader.Uname = \"\"\n\theader.Gname = \"\"\n\n\terr = tw.WriteHeader(header)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write header for %s: %s\", localpath, err)\n\t}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/writer.go#L104-L140","documentation":"tar.FileInfoHeader(fi, localpath) failed while converting the os.FileInfo into a tar header. This is thrown by the archive/tar machinery, not the filesystem, and is rare — it usually means the FileInfo came from an unsupported file type or the tar writer was constructed inconsistently.","triggerScenarios":"tar.FileInfoHeader returns an error for the stat'ed file — e.g. exotic file types or a malformed FileInfo on the target platform.","commonSituations":"Packaging special files (devices, sockets) instead of regular files or directories; platform edge cases; corrupted filesystem metadata.","solutions":["Confirm localpath points to a regular file or directory, not a device/socket/fifo (stat -c %F)","Exclude non-regular files from the packaging input list","If a tool is generating special files in your build tree, fix the generator"],"exampleFix":"// before\nerr := util.WriteFileToPackage(socketPath, pkgPath, tw)\n// after\nfi, _ := os.Stat(socketPath)\nif !fi.Mode().IsRegular() && !fi.IsDir() {\n    return fmt.Errorf(\"skipping non-regular file %s\", socketPath)\n}\nerr := util.WriteFileToPackage(socketPath, pkgPath, tw)","handlingStrategy":"validation","validationCode":"func isRegularOrDir(localpath string) error {\n    fi, err := os.Stat(localpath)\n    if err != nil { return err }\n    m := fi.Mode()\n    if !m.IsRegular() && !m.IsDir() {\n        return fmt.Errorf(\"%s is %v; only regular files/dirs are packageable\", localpath, m.Type())\n    }\n    return nil\n}","typeGuard":"func isPackageableFile(path string) bool {\n    fi, err := os.Stat(path)\n    return err == nil && (fi.Mode().IsRegular() || fi.IsDir())\n}","tryCatchPattern":"if err := util.WriteFileToPackage(localpath, pkgPath, tw); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed calculating FileInfoHeader\") {\n        return fmt.Errorf(\"unsupported file type in package input %s\", localpath)\n    }\n    return err\n}","preventionTips":["Only pass regular files or directories to WriteFileToPackage","Exclude sockets/devices/fifos generated by builds from the packaging set","Keep source metadata healthy; do not package from damaged filesystems"],"tags":["go","tar","archive","chaincode"],"backgroundTag":"tar-header-failure","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"}