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

panic: runtime error: invalid memory address or nil pointer dereference when docker-compose.yaml empty #476

Closed
ivosh opened this issue Oct 30, 2023 · 2 comments · Fixed by #485

Comments

@ivosh
Copy link

ivosh commented Oct 30, 2023

By accident, docker-compose.yaml happened to be an empty file.
IMO docker compose plugin should not crash on this singularity but rather complain with a useful error message.

How to reproduce:

  1. Install docker engine and docker compose plugin. I used RHEL 8.2 with the latest docker CE and docker-compose-plugin:
$ docker version
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:09:18 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:20 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
$ docker compose version
Docker Compose version v2.21.0
  1. Create an empty docker-compose.yaml file:
touch docker-compose.yaml
  1. Crash docker compose plugin with:
$ docker compose down
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x108bf33]

goroutine 1 [running]:
github.com/compose-spec/compose-go/loader.load({0x2638cb8, 0xc00011e010}, {{0x0, 0x0}, {0xc0001cd560, 0x1c}, {0xc0003cc120, 0x1, 0x1}, 0xc000131e90}, ...)
        github.com/compose-spec/[email protected]/loader/loader.go:343 +0x893
github.com/compose-spec/compose-go/loader.LoadWithContext({0x2638cb8, 0xc00011e010}, {{0x0, 0x0}, {0xc0001cd560, 0x1c}, {0xc0003cc120, 0x1, 0x1}, 0xc000131e90}, ...)
        github.com/compose-spec/[email protected]/loader/loader.go:242 +0x2a5
github.com/compose-spec/compose-go/cli.ProjectFromOptions(0xc0000cbe00)
        github.com/compose-spec/[email protected]/cli/options.go:402 +0x4f2
github.com/docker/compose/v2/cmd/compose.(*ProjectOptions).ToProject(0xc0000cb700, {0x0, 0x0, 0x0}, {0xc00052f748?, 0x375e558?, 0x375e558?})
        github.com/docker/compose/v2/cmd/compose/compose.go:221 +0xfb
github.com/docker/compose/v2/cmd/compose.(*ProjectOptions).projectOrName(0x417e50?, {0x0?, 0xc00052f828?, 0x417e50?})
        github.com/docker/compose/v2/cmd/compose/compose.go:180 +0x5c
github.com/docker/compose/v2/cmd/compose.runDown({0x2638c80, 0xc0002d6d70}, {0x2651338, 0xc0000c6600}, {0xc0000cb700, 0x0, 0x0, 0x0, 0x0, {0x0, ...}}, ...)
        github.com/docker/compose/v2/cmd/compose/down.go:80 +0x75
github.com/docker/compose/v2/cmd/compose.downCommand.func2({0x2638c80?, 0xc0002d6d70?}, {0x375e558?, 0xc0000061a0?, 0x1d12c3a?})
        github.com/docker/compose/v2/cmd/compose/down.go:59 +0x65
github.com/docker/compose/v2/cmd/compose.Adapt.func1({0x2638c80?, 0xc0002d6d70?}, 0x2?, {0x375e558?, 0x1?, 0xc00052f950?})
        github.com/docker/compose/v2/cmd/compose/compose.go:108 +0x36
github.com/docker/compose/v2/cmd/compose.AdaptCmd.func1(0xc000004c00, {0x375e558, 0x0, 0x0})
        github.com/docker/compose/v2/cmd/compose/compose.go:87 +0x21c
github.com/docker/compose/v2/cmd/cmdtrace.wrapRunE.func2(0xc000004c00?, {0x375e558?, 0x0?, 0x0?})
        github.com/docker/compose/v2/cmd/cmdtrace/cmd_span.go:80 +0x73
github.com/spf13/cobra.(*Command).execute(0xc000004c00, {0xc000098150, 0x0, 0x0})
        github.com/spf13/[email protected]/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc000282f00)
        github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:992
github.com/docker/cli/cli-plugins/plugin.RunPlugin(0x188?, 0xc000004600, {{0x22d0b8e, 0x5}, {0x22daca9, 0xb}, {0x2611938, 0x7}, {0x0, 0x0}, ...})
        github.com/docker/[email protected]+incompatible/cli-plugins/plugin/plugin.go:51 +0x130
github.com/docker/cli/cli-plugins/plugin.Run(0x240e410, {{0x22d0b8e, 0x5}, {0x22daca9, 0xb}, {0x2611938, 0x7}, {0x0, 0x0}, {0x0, ...}, ...})
        github.com/docker/[email protected]+incompatible/cli-plugins/plugin/plugin.go:64 +0xee
main.pluginMain()
        github.com/docker/compose/v2/cmd/main.go:37 +0xdf
main.main()
        github.com/docker/compose/v2/cmd/main.go:75 +0x198
@ndeloof
Copy link
Collaborator

ndeloof commented Nov 8, 2023

This has been fixed by 2a83d1c
I also proposed a test case to cover this scenario to prevent any regression with this

@ndeloof ndeloof closed this as completed Nov 8, 2023
@ivosh
Copy link
Author

ivosh commented Nov 8, 2023

Thank you, @ndeloof!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants