{"record":{"id":"d486fee047e94f3d","repo":"hyperledger/fabric","slug":"error-inspecting-next-tar-header","errorCode":null,"errorMessage":"error inspecting next tar header","messagePattern":"error inspecting next tar header","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/chaincode_package.go","lineNumber":186,"sourceCode":"\t\t\tfile.Close()\n\t\t}\n\t}()\n\n\tgzReader, err := gzip.NewReader(file)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"error reading as gzip stream\")\n\t}\n\n\ttarReader := tar.NewReader(gzReader)\n\n\tfor {\n\t\theader, err := tarReader.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"error inspecting next tar header\")\n\t\t}\n\n\t\tif header.Name != name {\n\t\t\tcontinue\n\t\t}\n\n\t\tif header.Typeflag != tar.TypeReg {\n\t\t\treturn nil, errors.Errorf(\"tar entry %s is not a regular file, type %v\", header.Name, header.Typeflag)\n\t\t}\n\n\t\treturn &TarFileStream{\n\t\t\tTarFile:    tarReader,\n\t\t\tFileStream: file,\n\t\t}, nil\n\t}\n\n\treturn nil, errors.Errorf(\"did not find file '%s' in package\", name)\n}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/chaincode_package.go#L168-L204","documentation":"This error is returned when tarReader.Next() fails mid-iteration while searching a package tar for the named entry. gzip decompression succeeded, but the tar payload is malformed — bad header checksum, truncated archive, or corrupt entries. It wraps the underlying tar error for the File helper shared by Metadata, MetadataBytes, and Code.","triggerScenarios":"Calling Metadata(), MetadataBytes(), or Code() on a file whose gzip layer decompresses but whose tar structure is corrupt or truncated before a valid EOF.","commonSituations":"Partial downloads, disks filling mid-write during packaging, archives edited/re-zipped by non-tar tools, or transmission modes (e.g. ASCII ftp) corrupting binary data.","solutions":["Repackage the chaincode with 'peer lifecycle chaincode package'.","Test archive integrity: tar -tzvf <package> should list all entries without errors.","Verify the file wasn't truncated (compare size/checksum with the source).","Avoid re-saving or post-processing the package with editors or text-mode transfers."],"exampleFix":"// before: re-zipping a partially extracted package\nzip corrupt-pkg.tgz *.json\n// after: recreate from source artifacts\npeer lifecycle chaincode package mycc.tgz --path ./src --lang golang --label mycc-v1","handlingStrategy":"validation","validationCode":"f, err := os.Open(pkgPath)\nif err != nil { return err }\ngr, err := gzip.NewReader(f)\nif err != nil { return fmt.Errorf(\"not gzip: %w\", err) }\ntr := tar.NewReader(gr)\nfor {\n\tif _, err := tr.Next(); err == io.EOF { break } else if err != nil {\n\t\treturn fmt.Errorf(\"package %s has corrupt tar: %w\", pkgPath, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"meta, err := p.Metadata(pkgPath)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error inspecting next tar header\") {\n\t\treturn fmt.Errorf(\"package %s corrupt, repackage it\", pkgPath)\n\t}\n\treturn err\n}","preventionTips":["Validate packages with 'tar -tzvf' immediately after creation.","Never post-edit or re-save package files.","Check disk space and transfer completion before installing.","Keep package files binary-safe end to end."],"tags":["tar","chaincode-package","corrupt-input"],"backgroundTag":"corrupt-tar-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"}