fix: remove restrictions on windows for NAME_MAX (#9469)

Fixes #9393
This commit is contained in:
Harshavardhana
2020-04-28 17:32:46 -07:00
committed by GitHub
parent b37a02cddf
commit ab77b216d1
4 changed files with 49 additions and 11 deletions
+21 -10
View File
@@ -108,20 +108,31 @@ func checkPathLength(pathName string) error {
return errFileNameTooLong
}
if runtime.GOOS == "windows" {
// Convert any '\' to '/'.
pathName = filepath.ToSlash(pathName)
// Disallow more than 1024 characters on windows, there
// are no known name_max limits on Windows.
if runtime.GOOS == "windows" && len(pathName) > 1024 {
return nil
}
// Check each path segment length is > 255
for len(pathName) > 0 && pathName != "." && pathName != SlashSeparator {
dir, file := slashpath.Dir(pathName), slashpath.Base(pathName)
// On Unix we reject paths if they are just '.', '..' or '/'
if pathName == "." || pathName == ".." || pathName == slashSeparator {
return errFileAccessDenied
}
if len(file) > 255 {
return errFileNameTooLong
// Check each path segment length is > 255 on all Unix
// platforms, look for this value as NAME_MAX in
// /usr/include/linux/limits.h
var count int64
for _, p := range pathName {
switch p {
case '/':
count = 0 // Reset
default:
count++
if count > 255 {
return errFileNameTooLong
}
}
pathName = dir
} // Success.
return nil
}