{"record":{"id":"8b5a01c0bd565c9a","repo":"hyperledger/fabric","slug":"tar-entry-s-is-not-a-regular-file-type-v","errorCode":null,"errorMessage":"tar entry %s is not a regular file, type %v","messagePattern":"tar entry (.+?) is not a regular file, type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/chaincode_package.go","lineNumber":194,"sourceCode":"\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}\n\ntype TarFileStream struct {\n\tTarFile    io.Reader\n\tFileStream io.Closer\n}\n\nfunc (tfs *TarFileStream) Read(p []byte) (int, error) {\n\treturn tfs.TarFile.Read(p)","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/chaincode_package.go#L176-L212","documentation":"When scanning the package tar for the requested entry (e.g. metadata.json or code.tar), the code found a matching header.Name but its Typeflag is not tar.TypeReg. The library only supports regular files inside chaincode packages, so directories, symlinks, or special files are rejected with this Errorf (not wrapped).","triggerScenarios":"Calling Metadata(), MetadataBytes(), or Code() where the tar entry matching the requested name is a directory entry, symlink, hardlink, or device node rather than a regular file.","commonSituations":"Hand-built tars that include directory entries (tar -czf out.tgz dir/ instead of the files), tars created with symlinked metadata.json, or tooling that repacks packages preserving links.","solutions":["Rebuild the tar so the target entry is a regular file (tar -czf out.tgz -C pkgdir metadata.json code.tar).","Remove directory/symlink entries: inspect with tar -tvzf and recreate from files only.","Replace symlinks with real file copies before packaging.","Use standard fabric packaging commands instead of manual tar construction."],"exampleFix":"// before: includes directory entries and symlinks\ntar -czf mycc.tgz pkgdir/\n// after: only regular files at top level\ncd pkgdir && tar -czf ../mycc.tgz metadata.json code.tar","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"tar\", \"-tvzf\", pkgPath).Output()\nif err != nil { return err }\nfor _, line := range strings.Split(string(out), \"\\n\") {\n\tif strings.TrimSpace(line) != \"\" && !strings.HasPrefix(line, \"-\") {\n\t\treturn fmt.Errorf(\"non-regular entry in %s: %s\", pkgPath, line)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if _, err := p.Metadata(pkgPath); err != nil {\n\tif strings.Contains(err.Error(), \"is not a regular file\") {\n\t\treturn fmt.Errorf(\"repackage %s: tar contains non-file entries\", pkgPath)\n\t}\n\treturn err\n}","preventionTips":["Build tars from files, not directories (avoid './' entries).","Replace symlinks with real copies before packaging.","Inspect 'tar -tvzf' output: first column must be '-' for every entry.","Use canonical fabric packaging tooling."],"tags":["tar","chaincode-package","entry-type"],"backgroundTag":"invalid-tar-entry-type","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"}