{"record":{"id":"67eb389b138ca584","repo":"larksuite/cli","slug":"not-a-regular-file-directories-devices-fifos-a-67eb38","errorCode":null,"errorMessage":"not a regular file (directories, devices, FIFOs, and sockets are refused)","messagePattern":"not a regular file \\(directories, devices, FIFOs, and sockets are refused\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/vfs/localfileio/openvalidated_windows.go","lineNumber":50,"sourceCode":"\t\t// map ErrPathValidation to a typed validation error, and the fd checks\n\t\t// are the same verdict the path checks make, one layer later.\n\t\treturn nil, &fileio.PathValidationError{Err: err}\n\t}\n\treturn f, nil\n}\n\n// inspectOpenedFile validates the opened handle. pre is nil when there is no\n// prior Stat to compare against.\nfunc inspectOpenedFile(f *os.File, pre os.FileInfo) error {\n\tpost, err := f.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot stat opened file: %w\", err)\n\t}\n\tif pre != nil && !os.SameFile(pre, post) {\n\t\treturn fmt.Errorf(\"file changed between validation and open\")\n\t}\n\tif !post.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file (directories, devices, FIFOs, and sockets are refused)\")\n\t}\n\tvar handleInfo syscall.ByHandleFileInformation\n\tif err := syscall.GetFileInformationByHandle(syscall.Handle(f.Fd()), &handleInfo); err != nil {\n\t\treturn fmt.Errorf(\"cannot inspect opened file links: %w\", err)\n\t}\n\tif handleInfo.NumberOfLinks > 1 {\n\t\treturn fmt.Errorf(\"file has multiple hard links, so the other names it can be reached by \" +\n\t\t\t\"cannot be checked (hint: copy the file and use the copy instead)\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":32,"sourceCodeEnd":62,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/vfs/localfileio/openvalidated_windows.go#L32-L62","documentation":"The opened handle points to something that is not a regular file — a directory, device, FIFO, or socket. The library only serves regular files through validated opens, so any other file type is refused after opening. This prevents reading from special objects or directories through the file API.","triggerScenarios":"Passing a directory path, a device path (e.g. \\\\.\\PhysicalDrive0, NUL), a named pipe, or a unix-domain socket path to openValidated on Windows.","commonSituations":"Constructing a path from user input that points at a directory, accidentally passing a COM port or device namespace path, pointing the CLI at a socket file created by a local server, or misconfigured workspace/file settings.","solutions":["Check the path with os.Stat and require stat.Mode().IsRegular() before calling","Remove any trailing path separator or wrong component so the path names the actual file, not its directory","Do not open device, pipe, or socket paths through this API; use the appropriate OS-specific mechanism instead","If input comes from users/config, validate the resolved path points at an expected regular file"],"exampleFix":"// before: no type check\nf, err := openValidated(userPath, nil)\n// after\ninfo, err := os.Stat(userPath)\nif err != nil { return err }\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file\", userPath)\n}\nf, err := openValidated(userPath, info)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil { return err }\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"refusing non-regular path %s (mode %s)\", path, info.Mode())\n}","typeGuard":"func isRegularFile(info os.FileInfo) bool { return info != nil && info.Mode().IsRegular() }","tryCatchPattern":"f, err := openValidated(path, pre)\nif err != nil && strings.Contains(err.Error(), \"not a regular file\") {\n    return fmt.Errorf(\"%s is a directory or special file; provide a path to a regular file\", path)\n}","preventionTips":["Stat and require Mode().IsRegular() before every validated open","Trim trailing separators and join paths carefully so the final component is the file, not its directory","Reject user/config-supplied paths that name devices, pipes, sockets, or directories"],"tags":["windows","filesystem","path-validation","regular-file"],"backgroundTag":"not-a-regular-file","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}