When mounting volumes: `panic: runtime error: index out of range`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Description
A panic is displayed when running a docker image with a volume mounted to some source paths on the host machine.
Steps to reproduce the issue:
- Pull any docker image
- Run docker image with a volume binding where the source path is an unsigned integer less than 10
For example:
docker pull ubuntu:18.04
docker run -v 0:/data ubuntu:18.04
Describe the results you received:
- A golang panic is raised.
- This occurs regardless of if a file exists with the name.
- This also occurs if the filename is quoted
docker run -v "0":/data ubuntu:18.04 - An integer equal or greater than 10 works as expected.
- A negative integer raises a descriptive error
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/docker/cli/cli/compose/loader.isFilePath(0xc000224498, 0x1, 0x5572cd090710)
/go/src/github.com/docker/cli/cli/compose/loader/volume.go:121 +0x11d
github.com/docker/cli/cli/compose/loader.populateType(0xc0002692a8)
/go/src/github.com/docker/cli/cli/compose/loader/volume.go:102 +0x76
github.com/docker/cli/cli/compose/loader.ParseVolume(0x7ffc63a8e696, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/go/src/github.com/docker/cli/cli/compose/loader/volume.go:44 +0x3f8
github.com/docker/cli/cli/command/container.parse(0xc0004b0500, 0xc000232580, 0xc000224040, 0x5, 0x0, 0x0, 0xc0004ba380)
/go/src/github.com/docker/cli/cli/command/container/opts.go:344 +0x291
github.com/docker/cli/cli/command/container.runRun(0x5572cbeb6220, 0xc000258000, 0xc0004b0500, 0xc00005fec0, 0xc000232580, 0x5572cb0d0f62, 0x5572ca3cee70)
/go/src/github.com/docker/cli/cli/command/container/run.go:81 +0x4c0
github.com/docker/cli/cli/command/container.NewRunCommand.func1(0xc0002d4a00, 0xc000028180, 0x1, 0x3, 0x0, 0x0)
/go/src/github.com/docker/cli/cli/command/container/run.go:47 +0xff
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc0002d4a00, 0xc00051d990, 0x3, 0x3, 0xc0002d4a00, 0xc00051d990)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:762 +0x467
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc00046b180, 0xc00051d980, 0x4, 0x4)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:852 +0x2ee
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:800
main.runDocker(0xc000258000, 0x5572cbe1e8c0, 0xc000010020)
/go/src/github.com/docker/cli/cmd/docker/docker.go:281 +0x1d5
main.main()
/go/src/github.com/docker/cli/cmd/docker/docker.go:292 +0xf3
Describe the results you expected:
I expect either the command to succeed if the file exists or an error saying the file does not exist.
Additional information you deem important (e.g. issue happens only occasionally):
Output of docker version:
Client: Docker Engine - Community
Version: 19.03.4
API version: 1.40
Go version: go1.12.10
Git commit: 9013bf583a
Built: Fri Oct 18 15:54:09 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.4
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: 9013bf583a
Built: Fri Oct 18 15:52:40 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
Output of docker info:
Client:
Debug Mode: false
Server:
Containers: 37
Running: 0
Paused: 0
Stopped: 37
Images: 130
Server Version: 19.03.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-66-generic
Operating System: Ubuntu 18.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.41GiB
Name: consistency
ID: UK7B:2DQI:KBNU:I5SR:S3AM:ATYF:MNZD:QRD6:DO53:U6SY:67JG:KJGG
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
Additional environment details (AWS, VirtualBox, physical, etc.):
Thinkpad X1 Carbon 7th Generation
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in cli/compose/loader/volume.go, following the stack trace through ParseVolume, populateType, and isFilePath. Reproduce the issue with docker run -v 0:/data ubuntu:18.04 and compare it with a source path of 10 or greater. Done means the command no longer panics and either succeeds for an existing path or reports that the path does not exist.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100