-
Couldn't load subscription status.
- Fork 18.4k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Unfortunatemodules
Milestone
Description
What version of Go are you using (go version)?
$ go version go version go1.12.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GOARCH="amd64" GOBIN="/home/gheibi/.go/bin/" GOCACHE="/home/gheibi/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/gheibi/.go/" GOPROXY="" GORACE="" GOROOT="/local/go1.12.1.linux_amd64/go" GOTMPDIR="" GOTOOLDIR="/local/go1.12.1.linux_amd64/go /pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build865790926=/tmp/go-build"
What did you do?
$grep -A12 "func isVendoredPackage" $GOROOT/src/cmd/go/internal/modfetch/coderepo.go
go/src/cmd/go/internal/modfetch/coderepo.go
Lines 632 to 642 in c8aaec2
| func isVendoredPackage(name string) bool { | |
| var i int | |
| if strings.HasPrefix(name, "vendor/") { | |
| i += len("vendor/") | |
| } else if j := strings.Index(name, "/vendor/"); j >= 0 { | |
| i += len("/vendor/") | |
| } else { | |
| return false | |
| } | |
| return strings.Contains(name[i:], "/") | |
| } |
What did you expect to see?
func isVendoredPackage(name string) bool {
var i int
if strings.HasPrefix(name, "vendor/") {
i += len("vendor/")
} else if j := strings.Index(name, "/vendor/"); j >= 0 {
i += j + len("/vendor/")
} else {
return false
}
return strings.Contains(name[i:], "/")
}
What did you see instead?
The function is not documented, but it is obvious that it is not doing what the intention is.
It seems that the intention is to match against this regex: (^vendor/|/vendor/).*/
But in fact it does random match by skipping first 8 bytes in case the input contains /vendor/.
The fix is to add the j to the i as states above.
It is quite important to fix it early on, because it may cause go-modules with different hashes and a late fix can cause more hash mismatch of the same content (defy the immutability logic).
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Unfortunatemodules