Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: panic: runtime error: slice bounds out of range #12156

Closed
jbuberel opened this issue Aug 15, 2015 · 3 comments
Closed

cmd/go: panic: runtime error: slice bounds out of range #12156

jbuberel opened this issue Aug 15, 2015 · 3 comments
Milestone

Comments

@jbuberel
Copy link

Does not appear to be a dup of #11414

Problem is reproducible on tip +e8c4a5b as well as go1.5rc1 tag. Added a few printfs just before line 453:

jbuberel@ubuntu:~/vtest/src$ go run p/command.go 
parent.ImportPath: [p]
len(parent.ImportPath)-chopped: [-5]
vpath: [vendor/github.com/gorilla/mux]
panic: runtime error: slice bounds out of range

Full output:

$ go run p/cmd.go 
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.vendoredImportPath(0xc82010bc00, 0xc8201114c1, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/jbuberel/go15/src/cmd/go/pkg.go:453 +0x540
main.loadImport(0xc8201114c1, 0x16, 0xc820110fa0, 0x1a, 0xc82010bc00, 0xc8201078c0, 0xc8200efa70, 0x1, 0x1, 0x1, ...)
        /home/jbuberel/go15/src/cmd/go/pkg.go:317 +0x138e
main.(*Package).load(0xc82010bc00, 0xc8201078c0, 0xc8200d2900, 0x0, 0x0, 0x0)
        /home/jbuberel/go15/src/cmd/go/pkg.go:899 +0x42e1
main.goFilesPackage(0xc82000a350, 0x1, 0x1, 0x8)
        /home/jbuberel/go15/src/cmd/go/build.go:750 +0x836
main.runRun(0xba6020, 0xc82000a350, 0x1, 0x1)
        /home/jbuberel/go15/src/cmd/go/run.go:87 +0x479
main.main()
        /home/jbuberel/go15/src/cmd/go/main.go:181 +0x782

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /home/jbuberel/go15/src/runtime/asm_amd64.s:1696 +0x1

goroutine 5 [syscall]:
os/signal.loop()
        /home/jbuberel/go15/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
        /home/jbuberel/go15/src/os/signal/signal_unix.go:28 +0x37
jbuberel@ubuntu:~/vtest/src$ mv ../vendor/ ../v
jbuberel@ubuntu:~/vtest/src$ go run p/cmd.go   
p/cmd.go:4:2: cannot find package "github.com/gorilla/mux" in any of:
        /home/jbuberel/go15/src/github.com/gorilla/mux (from $GOROOT)
        /home/jbuberel/vtest/src/github.com/gorilla/mux (from $GOPATH)
jbuberel@ubuntu:~/vtest/src$ mv p/cmd.go p/command.go
jbuberel@ubuntu:~/vtest/src$ go run p/command.go 
p/command.go:4:2: cannot find package "github.com/gorilla/mux" in any of:
        /home/jbuberel/go15/src/github.com/gorilla/mux (from $GOROOT)
        /home/jbuberel/vtest/src/github.com/gorilla/mux (from $GOPATH)

Version, build and directory configuration:

$ go version
go version devel +e8c4a5b Sat Aug 15 17:38:56 2015 +0000 linux/amd64
jbuberel@ubuntu:~/vtest/src$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jbuberel/vtest"
GORACE=""
GOROOT="/home/jbuberel/go15"
GOTOOLDIR="/home/jbuberel/go15/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
jbuberel@ubuntu:~/vtest/src$ cd ../
jbuberel@ubuntu:~/vtest$ cd ../
jbuberel@ubuntu:~$ tree vtest/
vtest/
|-- src
|   `-- p
|       `-- command.go
`-- vendor
    `-- github.com
        `-- gorilla
            |-- context
            |   |-- context.go
            |   |-- context_test.go
            |   |-- doc.go
            |   |-- LICENSE
            |   `-- README.md
            `-- mux
                |-- bench_test.go
                |-- doc.go
                |-- LICENSE
                |-- mux.go
                |-- mux_test.go
                |-- old_test.go
                |-- README.md
                |-- regexp.go
                `-- route.go

Contents of command.go:

package main

import (
        "fmt"
        "github.com/gorilla/mux"
)

func main() {
        m := mux.NewRouter()
        fmt.Println(m)
}
@jbuberel
Copy link
Author

Moving the vendor directory out of the root of $GOPATH and the problem goes away:

vendor in $GOPATH root causes panic:

$ tree ~/vtest
/home/jbuberel/vtest
|-- src
|   `-- package
|       `-- command.go
`-- vendor
    `-- github.com
        `-- gorilla
            |-- context
            |   |-- context.go
            |   |-- context_test.go
            |   |-- doc.go
            |   |-- LICENSE
            |   `-- README.md
            `-- mux
                |-- bench_test.go
                |-- doc.go
                |-- LICENSE
                |-- mux.go
                |-- mux_test.go
                |-- old_test.go
                |-- README.md
                |-- regexp.go
                `-- route.go
$ go run command.go 
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.vendoredImportPath(0xc82010bc00, 0xc82010f421, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/jbuberel/go15/src/cmd/go/pkg.go:453 +0x540
main.loadImport(0xc82010f421, 0x16, 0xc8200ef920, 0x20, 0xc82010bc00, 0xc8201078c0, 0xc8200efbc0, 0x1, 0x1, 0x1, ...)
        /home/jbuberel/go15/src/cmd/go/pkg.go:317 +0x138e
main.(*Package).load(0xc82010bc00, 0xc8201078c0, 0xc8200d2900, 0x0, 0x0, 0x0)
        /home/jbuberel/go15/src/cmd/go/pkg.go:899 +0x42e1
main.goFilesPackage(0xc82000a350, 0x1, 0x1, 0x8)
        /home/jbuberel/go15/src/cmd/go/build.go:750 +0x836
main.runRun(0xba4fe0, 0xc82000a350, 0x1, 0x1)
        /home/jbuberel/go15/src/cmd/go/run.go:87 +0x479
main.main()
        /home/jbuberel/go15/src/cmd/go/main.go:181 +0x782

vendor in $GOPATH/src works correctly:

$ tree ~/vtest
/home/jbuberel/vtest
`-- src
    |-- package
    |   `-- command.go
    `-- vendor
        `-- github.com
            `-- gorilla
                |-- context
                |   |-- context.go
                |   |-- context_test.go
                |   |-- doc.go
                |   |-- LICENSE
                |   `-- README.md
                `-- mux
                    |-- bench_test.go
                    |-- doc.go
                    |-- LICENSE
                    |-- mux.go
                    |-- mux_test.go
                    |-- old_test.go
                    |-- README.md
                    |-- regexp.go
                    `-- route.go

7 directories, 15 files
jbuberel@ubuntu:~/vtest/src/package$ go run command.go 
&{<nil> <nil> [] map[] false false}

@rsc rsc added this to the Go1.5Maybe milestone Aug 16, 2015
@rsc
Copy link
Contributor

rsc commented Aug 18, 2015

Nice, thanks.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/13674 mentions this issue.

@rsc rsc closed this as completed in 9e26cde Aug 18, 2015
@mikioh mikioh modified the milestones: Go1.5, Go1.5Maybe Aug 18, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants