{"record":{"id":"63210b98be383a19","repo":"pulumi/pulumi","slug":"unexpected-file-mode-v-for-s","errorCode":null,"errorMessage":"unexpected file mode %v for %s","messagePattern":"unexpected file mode (.+?) for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/common/util/archive/archive.go","lineNumber":94,"sourceCode":"\t\tif _, err := os.Stat(path); err != nil {\n\t\t\tif err = os.MkdirAll(path, 0o0700); err != nil {\n\t\t\t\treturn fmt.Errorf(\"extracting dir %s: %w\", path, err)\n\t\t\t}\n\t\t}\n\tcase tar.TypeReg:\n\t\t// Create any directories as needed. Some tools (notably `npm pack`) don't list\n\t\t// directories individually, so if a file is in a directory that doesn't exist, we need\n\t\t// to create it here.\n\t\tdir := filepath.Dir(path)\n\t\tif _, err := os.Stat(dir); err != nil {\n\t\t\tif err = os.MkdirAll(dir, 0o0700); err != nil {\n\t\t\t\treturn fmt.Errorf(\"extracting dir %s: %w\", dir, err)\n\t\t\t}\n\t\t}\n\n\t\t// Expand files into the target directory.\n\t\tif header.Mode > math.MaxUint32 {\n\t\t\treturn fmt.Errorf(\"unexpected file mode %v for %s\", header.Mode, header.Name)\n\t\t}\n\t\tdst, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"opening file %s for extraction: %w\", path, err)\n\t\t}\n\t\tdefer contract.IgnoreClose(dst)\n\n\t\t// We're not concerned with potential tarbombs, so disable gosec.\n\t\tif _, err = io.Copy(dst, r); err != nil {\n\t\t\treturn fmt.Errorf(\"untarring file %s: %w\", path, err)\n\t\t}\n\tcase tar.TypeSymlink:\n\t\t// Guard against symlinks that point outside the extraction directory.\n\t\ttarget := header.Linkname\n\t\tif !filepath.IsAbs(target) {\n\t\t\t//nolint:gosec // The resolved target is checked against the destination directory below.\n\t\t\ttarget = filepath.Join(filepath.Dir(path), target)\n\t\t}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/common/util/archive/archive.go#L76-L112","documentation":"The tar header's Mode field (int64) exceeds math.MaxUint32, so it cannot be safely narrowed to an os.FileMode. The extractor rejects the entry rather than truncating the mode bits.","triggerScenarios":"Extracting a tar archive containing a regular-file entry whose mode field is > 0xFFFFFFFF — only possible with malformed or crafted tar headers, since standard tools write modes well under 0o7777.","commonSituations":"Corrupted download of a plugin tarball; hand-crafted or third-party archive with garbage in the mode field; bit-rotted or truncated archive.","solutions":["Re-download the plugin/archive and verify its checksum","Recreate the archive with a standard tool (tar/gzip) so mode fields are valid","If you produce archives programmatically, clamp/validate header.Mode before writing the tar"],"exampleFix":"// before\nheader.Mode = 0x1FFFFFFFF // > MaxUint32\n// after\nheader.Mode = 0o755 // valid POSIX mode","handlingStrategy":"validation","validationCode":"f, err := os.Open(tgzPath)\nif err != nil { return err }\ndefer f.Close()\nsum := sha256.Sum256(readAll(f))\nif !bytes.Equal(sum[:], expectedSum[:]) { return fmt.Errorf(\"archive checksum mismatch; archive may be corrupted\") }","typeGuard":null,"tryCatchPattern":"if err := extractFile(r, header, dir); err != nil {\n\tif strings.Contains(err.Error(), \"unexpected file mode\") {\n\t\treturn fmt.Errorf(\"archive %s has a malformed tar header; re-download it\", tgzPath)\n\t}\n\treturn err\n}","preventionTips":["Always verify checksums of downloaded plugin archives","Reject archives not produced by standard tar tooling","Clamp header.Mode when writing your own tars"],"tags":["go","archive","tar","validation"],"backgroundTag":"invalid-tar-file-mode","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}