From 0462b9ace3713db6d4ca9208ba35c3b4aa5d14ce Mon Sep 17 00:00:00 2001 From: valoq Date: Thu, 11 Jun 2026 05:18:20 +0200 Subject: [PATCH] fix: prevent copying a directory into itself (#2608) --- copy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/copy.go b/copy.go index 355b22f6..184b3797 100644 --- a/copy.go +++ b/copy.go @@ -124,6 +124,11 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, 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 { if err != nil { errs <- fmt.Errorf("walk: %w", err)