{"record":{"id":"ec90b134dd928481","repo":"hashicorp/packer","slug":"failed-to-create-tar-header-for-s-s","errorCode":null,"errorMessage":"Failed to create tar header for %s: %s","messagePattern":"Failed to create tar header for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":395,"sourceCode":"func createTarArchive(files []string, output io.WriteCloser) error {\n\tarchive := tar.NewWriter(output)\n\tdefer archive.Close()\n\n\tfor _, path := range files {\n\t\tfile, err := os.Open(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Unable to read file %s: %s\", path, err)\n\t\t}\n\t\tdefer file.Close()\n\n\t\tfi, err := file.Stat()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Unable to get fileinfo for %s: %s\", path, err)\n\t\t}\n\n\t\theader, err := tar.FileInfoHeader(fi, path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to create tar header for %s: %s\", path, err)\n\t\t}\n\n\t\t// workaround for archive format on go >=1.10\n\t\tsetHeaderFormat(header)\n\n\t\tif err := archive.WriteHeader(header); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to write tar header for %s: %s\", path, err)\n\t\t}\n\n\t\tif _, err := io.Copy(archive, file); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to copy %s data to archive: %s\", path, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createZipArchive(files []string, output io.WriteCloser) error {\n\tarchive := zip.NewWriter(output)","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L377-L413","documentation":"tar.FileInfoHeader failed to build a tar header from a file's metadata in Packer's compress post-processor. Even with valid stat data, the tar library can reject file metadata it cannot represent (e.g. irregular file types or unsupported mode bits), aborting archive creation.","triggerScenarios":"createTarArchive calls tar.FileInfoHeader(fi, path) after a successful Stat and the tar package returns an error — typically for a file whose type cannot be encoded in a tar header (device files, sockets, FIFOs) or invalid metadata.","commonSituations":"An artifact listing a special file (socket/FIFO/device) produced by an unusual builder or plugin; very unusual file modes; Go version/library changes altering FileInfoHeader strictness.","solutions":["Identify the offending file from the error and check its type (stat <file>)","Ensure artifacts contain only regular files; remove/replace special files upstream","Update Packer to a version with current tar-library behavior fixes","Fall back to archive = \"zip\" if the artifact set includes non-regular files"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-flight: only regular files can get valid tar headers\nfor _, p := range artifact.Files() {\n    fi, err := os.Stat(p)\n    if err != nil { return err }\n    if !fi.Mode().IsRegular() {\n        return fmt.Errorf(\"%s is not a regular file (mode %s); tar cannot archive it\", p, fi.Mode())\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go: detect header failure and fall back to zip (tolerates special files)\nif err != nil && strings.Contains(err.Error(), \"Error creating tar\") &&\n    strings.Contains(err.Error(), \"Failed to create tar header\") {\n    cfg.Archive = \"zip\"\n    return pp.PostProcess(ctx, ui, artifact)\n}","preventionTips":["Ensure builders emit only regular files as artifacts","Filter sockets/FIFOs/devices out of the artifact before compression","Keep Packer updated for tar-library behavior changes","Test the full pipeline after changing builders that produce unusual outputs"],"tags":["packer","post-processor","tar","archive"],"backgroundTag":"tar-header-creation-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}