mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
Safely use unsafe.Pointer to avoid crashes on ARM (#8027)
Refactor the Dirent parsing code such that when we calculate offsets are correct based on the platform This PR fixes a silent potential crash on ARM architecture.
This commit is contained in:
@@ -57,9 +57,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
|
||||
data := &syscall.Win32finddata{}
|
||||
|
||||
remaining := count
|
||||
done := false
|
||||
for !done {
|
||||
for count != 0 {
|
||||
e := syscall.FindNextFile(syscall.Handle(d.Fd()), data)
|
||||
if e != nil {
|
||||
if e == syscall.ERROR_NO_MORE_FILES {
|
||||
@@ -74,7 +72,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
}
|
||||
}
|
||||
name := syscall.UTF16ToString(data.FileName[0:])
|
||||
if name == "." || name == ".." { // Useless names
|
||||
if name == "" || name == "." || name == ".." { // Useless names
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
@@ -101,10 +99,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
default:
|
||||
entries = append(entries, name)
|
||||
}
|
||||
if remaining > 0 {
|
||||
remaining--
|
||||
done = remaining == 0
|
||||
}
|
||||
count--
|
||||
}
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user