{"record":{"id":"77735c6638abf54d","repo":"slimtoolkit/slim","slug":"bad-file-s","errorCode":null,"errorMessage":"bad file - %s","messagePattern":"bad file - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/fsutil/fsutil.go","lineNumber":1425,"sourceCode":"\t\t\t}\n\n\t\t\tth.Name = fpRewrite(fname, true, addPrefix)\n\t\t\tif err := tw.WriteHeader(th); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tf, err := os.Open(fname)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tdefer close(f)\n\t\t\tif _, err := io.CopyN(tw, f, th.Size); err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot write %s file: %w\", fname, err)\n\t\t\t}\n\t\t} else {\n\t\t\tlog.Errorf(\"fsutil.ArchiveFiles: bad file - %s\", fname)\n\t\t\treturn fmt.Errorf(\"bad file - %s\", fname)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc ArchiveDir(afname string,\n\td2aname string,\n\ttrimPrefix string,\n\taddPrefix string) error {\n\tdirInfo, err := os.Stat(d2aname)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !dirInfo.IsDir() {\n\t\treturn fmt.Errorf(\"not a directory\")\n\t}","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/util/fsutil/fsutil.go#L1407-L1443","documentation":"ArchiveFiles rejects any input file entry that fails its sanity check (non-regular file, e.g. a directory, symlink, socket, or a file whose stat fails in a way that disqualifies it). It logs \"fsutil.ArchiveFiles: bad file\" and returns immediately, so the entire archive is abandoned rather than skipped.","triggerScenarios":"Passing a path that is not a regular file to fsutil.ArchiveFiles (via Archive or OnCommand) — most commonly a directory path, a dangling symlink, or a special device file.","commonSituations":"Globbing patterns that expand to directories, config that lists a directory instead of files, or symlinks left pointing at removed targets.","solutions":["Verify each input path is a regular file (os.Stat + Mode().IsRegular()) before calling ArchiveFiles.","Resolve symlinks to real files or remove dangling ones from the input list.","Filter directories out of glob results before passing the list to ArchiveFiles."],"exampleFix":"// before\nfsutil.ArchiveFiles(tw, []string{\"/data\", \"/data/a.txt\"})\n// after\ninfo, _ := os.Stat(\"/data/a.txt\")\nif info.Mode().IsRegular() {\n    fsutil.ArchiveFiles(tw, []string{\"/data/a.txt\"})\n}","handlingStrategy":"validation","validationCode":"func onlyRegularFiles(paths []string) ([]string, error) {\n    var out []string\n    for _, p := range paths {\n        fi, err := os.Stat(p)\n        if err != nil { return nil, err }\n        if fi.Mode().IsRegular() { out = append(out, p) }\n    }\n    return out, nil\n}","typeGuard":null,"tryCatchPattern":"if err := fsutil.ArchiveFiles(tw, files); err != nil {\n    if strings.HasPrefix(err.Error(), \"bad file - \") {\n        log.Warnf(\"skipping invalid input: %v\", err)\n    }\n    return err\n}","preventionTips":["Filter glob results to regular files only before archiving.","Resolve and verify symlinks point to existing regular files.","Keep explicit file lists instead of passing directories."],"tags":["filesystem","archive","input-validation"],"backgroundTag":"invalid-archive-input","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}