fix: prevent copying a directory into itself (#2608)

This commit is contained in:
valoq authored and GitHub committed 2026-06-11 13:18:20 +10:00
1 parent 583e78b727
commit 0462b9ace3
1 file changed
+5
+5
View File
@@ -124,6 +124,11 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
dst = newPath dst = newPath
} }
if rel, err := filepath.Rel(src, dst); err == nil && rel != "." && !strings.HasPrefix(rel, "..") {
errs <- fmt.Errorf("cannot copy %s into a subdirectory of itself", src)
continue
}
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
errs <- fmt.Errorf("walk: %w", err) errs <- fmt.Errorf("walk: %w", err)