Skip to content

path/filepath: Rel hangs in an infinite loop on Windows for a UNC volume root with a trailing separator #79784

@drakkan

Description

@drakkan

Go version

go version go1.26.3 windows/amd64

What did you do?

On Windows, filepath.Rel never returns when the base path is a UNC volume root (\\host\share) and the target path is the same volume root with a trailing separator.

filepath.Clean does not normalize this away: it preserves the trailing separator on a volume root (the UNC share root is treated like C:\), so the two arguments stay different and Rel loops.

package main

import (
      "fmt"
      "path/filepath"
)
 
func main() {
      // filepath.Clean(`\\host\share\`) == `\\host\share\` (trailing separator kept,
      // as for any volume root), so Clean does not avoid the problem.
      fmt.Println(filepath.Rel(`\\host\share`, filepath.Clean(`\\host\share\`)))
}

This is pure string manipulation, no filesystem access, so the share does not need to exist, and GOOS=windows is the only requirement.

What did you see instead?

The call never returns; the goroutine consumes a full CPU core indefinitely.

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions