From 1c085f7d1a807405f14719aa81350c200bec8d66 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 1 Sep 2020 09:33:16 -0700 Subject: [PATCH] Fix crash on Windows when crawling (#10385) * readDirN: Check if file is directory `syscall.FindNextFile` crashes if the handle is a file. `errFileNotFound` matches 'unix' functionality: https://github.com/minio/minio/blob/d19b434ffceb005d0673c53bf28209559a536ed3/cmd/os-readdir_unix.go#L106 Fixes #10384 --- cmd/os-readdir_windows.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/os-readdir_windows.go b/cmd/os-readdir_windows.go index 191ad6a24..74e98a734 100644 --- a/cmd/os-readdir_windows.go +++ b/cmd/os-readdir_windows.go @@ -19,6 +19,7 @@ package cmd import ( + "io" "os" "syscall" ) @@ -79,10 +80,16 @@ func readDirN(dirPath string, count int) (entries []string, err error) { } defer f.Close() + // Check if file or dir. This is the quickest way. + _, err = f.Seek(0, io.SeekStart) + if err == nil { + return nil, errFileNotFound + } data := &syscall.Win32finddata{} + handle := syscall.Handle(f.Fd()) for count != 0 { - e := syscall.FindNextFile(syscall.Handle(f.Fd()), data) + e := syscall.FindNextFile(handle, data) if e != nil { if e == syscall.ERROR_NO_MORE_FILES { break