{"record":{"id":"a02068bd8db4c036","repo":"hyperledger/fabric","slug":"illegal-file-mode-in-payload-s","errorCode":null,"errorMessage":"illegal file mode in payload: %s","messagePattern":"illegal file mode in payload: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/golang/platform.go","lineNumber":102,"sourceCode":"\ttr := tar.NewReader(gr)\n\tfor {\n\t\theader, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// maintain check for conforming paths for validation\n\t\tif !re.MatchString(header.Name) {\n\t\t\treturn fmt.Errorf(\"illegal file name in payload: %s\", header.Name)\n\t\t}\n\n\t\t// only files and directories; no links or special files\n\t\tmode := header.FileInfo().Mode()\n\t\tif mode&^(os.ModeDir|0o777) != 0 {\n\t\t\treturn fmt.Errorf(\"illegal file mode in payload: %s\", header.Name)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Directory constant copied from tar package.\nconst c_ISDIR = 0o40000\n\n// Default compression to use for production. Test packages disable compression.\nvar gzipCompressionLevel = gzip.DefaultCompression\n\n// GetDeploymentPayload creates a gzip compressed tape archive that contains the\n// required assets to build and run go chaincode.\n//\n// NOTE: this is only used at the _client_ side by the peer CLI.\nfunc (p *Platform) GetDeploymentPayload(codepath string) ([]byte, error) {\n\tcodeDescriptor, err := DescribeCode(codepath)","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/golang/platform.go#L84-L120","documentation":"During tar validation, ValidateCodePackage checks each entry's file mode and allows only regular files and directories (mode bits within 0o777 or ModeDir). Entries with setuid/setgid bits, symlinks, devices, or other special file types trigger this error.","triggerScenarios":"Calling ValidateCodePackage on a package whose tar contains a symlink, hardlink, fifo, socket, or device entry, or permission bits outside 0o777 (e.g. setuid files).","commonSituations":"Packaging symlinks from node_modules-like trees, archiving with flags preserving special files, or files with setgid group-exec bits from shared build dirs.","solutions":["Recreate the tar with only regular files and directories (tar --format=ustar without symlinks).","Replace symlinks with real copies of the files before packaging.","Normalize permissions to standard values (e.g. chmod 755/644) before archiving."],"exampleFix":"// before: symlink included\ntar -czf code.tar.gz src link-to-src\n// after: dereference symlinks\ntar -czhf code.tar.gz src","handlingStrategy":"validation","validationCode":"func entryModesOK(tgz []byte) error {\n\tgr, _ := gzip.NewReader(bytes.NewReader(tgz))\n\ttr := tar.NewReader(gr)\n\tfor {\n\t\th, err := tr.Next()\n\t\tif err == io.EOF { return nil }\n\t\tif err != nil { return err }\n\t\tm := h.FileInfo().Mode()\n\t\tif m&^(os.ModeDir|0o777) != 0 { return fmt.Errorf(\"bad mode: %s\", h.Name) }\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := platform.ValidateCodePackage(pkg); err != nil {\n\tif strings.Contains(err.Error(), \"illegal file mode in payload\") {\n\t\t// repackage with symlinks dereferenced (tar -h) and plain permissions\n\t}\n}","preventionTips":["Archive with tar -h to dereference symlinks","Normalize file modes to 644/755 before packaging","Never include devices, fifos, or sockets in chaincode packages"],"tags":["chaincode","tar","file-mode","hyperledger-fabric"],"backgroundTag":"illegal-file-mode-in-package","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"}