{"record":{"id":"d194900e41c221fa","repo":"AlistGo/alist","slug":"invalid-input-file-path-w","errorCode":null,"errorMessage":"invalid input file path: %w","messagePattern":"invalid input file path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/local/util.go","lineNumber":69,"sourceCode":"\t}\n\tif strings.ContainsAny(cleaned, \";&|`$<>!\\n\\r\\x00\") {\n\t\treturn \"\", fmt.Errorf(\"file path contains invalid characters: %s\", path)\n\t}\n\tinfo, err := os.Stat(cleaned)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"file path is not accessible: %w\", err)\n\t}\n\tif !info.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"path is not a regular file: %s\", cleaned)\n\t}\n\treturn cleaned, nil\n}\n\n// resizeImageToBufferWithFFmpegGo 使用 ffmpeg-go 调整图片大小并输出到内存缓冲区\nfunc resizeImageToBufferWithFFmpegGo(inputFile string, width int, outputFormat string /* e.g., \"image2pipe\", \"png_pipe\", \"mjpeg\" */) (*bytes.Buffer, error) {\n\tsanitized, err := sanitizeFilePath(inputFile)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid input file path: %w\", err)\n\t}\n\tinputFile = sanitized\n\n\toutBuffer := bytes.NewBuffer(nil)\n\n\t// Determine codec based on desired output format for piping\n\t// For generic image piping, 'image2' is often used with -f image2pipe\n\t// For specific formats to buffer, you might specify the codec directly\n\tvar vcodec string\n\tswitch outputFormat {\n\tcase \"png_pipe\": // if you want to ensure PNG format in buffer\n\t\tvcodec = \"png\"\n\tcase \"mjpeg\": // if you want to ensure JPEG format in buffer\n\t\tvcodec = \"mjpeg\"\n\t\t// default or \"image2pipe\" could leave codec choice more to ffmpeg or require -c:v later\n\t}\n\n\toutputArgs := ffmpeg.KwArgs{","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/local/util.go#L51-L87","documentation":"Thrown by resizeImageToBufferWithFFmpegGo when sanitizeFilePath rejects the path of an image about to be resized for a thumbnail. sanitizeFilePath enforces four rules: the path must be absolute, must not contain shell metacharacters (;;&|`$<>!\\n\\r\\x00), must be stat-able by the process, and must be a regular file. The wrapped error names which rule failed ('file path must be absolute', 'file path contains invalid characters', 'file path is not accessible', 'path is not a regular file').","triggerScenarios":"Calling getThumb on a local driver with useFFmpeg=true where the object's path is relative, contains a character like ';' or '$' or a newline in the filename, points to a symlink target that no longer exists, or points to a directory/fifo/device instead of a regular file.","commonSituations":"Filenames with shell metacharacters (e.g. 'photo;$1.png'), files deleted between directory listing and thumbnail request, permission-restricted mounts, or symlinked media directories on Windows volumes where ModeIrregular is set.","solutions":["Check the wrapped error message to identify which sanitizeFilePath rule failed","If the path is relative, ensure the local driver's root and the object's GetPath() produce absolute paths","Rename files containing ; & | ` $ < > ! or newlines, or relax the metacharacter check if you trust the input (ffmpeg-go does not use a shell)","Verify the file still exists and is readable: stat <path> as the same user running the process"],"exampleFix":"// before: relative or metachar path passed through\nimgBuf, err := resizeImageToBufferWithFFmpegGo(file.GetPath(), d.thumbPixel, \"image2pipe\")\n\n// after: resolve to an absolute, cleaned path first and skip files known to be problematic\nfullPath := file.GetPath()\nif !filepath.IsAbs(fullPath) {\n    fullPath = filepath.Join(d.RootFolderPath, fullPath)\n}\nimgBuf, err := resizeImageToBufferWithFFmpegGo(fullPath, d.thumbPixel, \"image2pipe\")\nif err != nil {\n    // fall back to no thumbnail rather than failing the listing\n    return nil, nil, nil\n}","handlingStrategy":"validation","validationCode":"func validThumbPath(path string) bool {\n    abs, err := filepath.Abs(path)\n    if err != nil {\n        return false\n    }\n    info, err := os.Stat(abs)\n    return err == nil && info.Mode().IsRegular()\n}","typeGuard":null,"tryCatchPattern":"In Go: imgBuf, err := resizeImageToBufferWithFFmpegGo(path, w, \"image2pipe\"); if err != nil { log thumbnail failure and degrade to a listing without thumbnails — never propagate to the caller of getThumb }","preventionTips":["Ensure local driver object paths are always absolute before thumbnail work","Treat thumbnail generation as best-effort: on error return nil thumb, not an error","Avoid filenames with shell metacharacters, or relax the sanitizer knowing ffmpeg-go passes argv directly"],"tags":["filesystem","path-validation","thumbnail","local-driver","ffmpeg"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}