buildkite / buildkite/agent

[crash] Panic due to "unhashable type" when calling `ParseDefinition`

Open
#1,337 1 comment 0 reactions 0 assignees View on GitHub
bug yaml
Dominant language
Go
Stars
1.1k
Forks
378
Avg merge
2d 6h
Merged PRs (30d)
74

Description

**Summary:**

During the decoding of some specific bytes, the function `ParseDefinition` will trigger a panic and make the complete program/process to crash.

**Description:**

This panic bug occurs when calling `yaml.Unmarshal(b, &parsed)` with specific data.
link: https://github.com/buildkite/agent/blob/30f8cc6526b88833d0411bcbba1527862c3a5207/agent/plugin/definition.go#L31

## Steps To Reproduce:

STEP 1: create a go project: `mkdir testing; touch main.go; touch go.mod`
STEP 2: `go.mod` content
``` golang
module main

go 1.15

replace github.com/buildkite/agent => ../

require (
github.com/buildkite/agent v0.0.0-00010101000000-000000000000
github.com/buildkite/agent/v3 v3.25.0 // indirect
)

```

STEP 3: `main.go` content

``` golang
package main

import (
plugin "github.com/buildkite/agent/agent/plugin"
)

func repro_ParseDefinition(){
data := []byte(":::::\x0d \x0d::\x0d \x0d-\x0d\x0d-\x0d\x0d?\x0d\x0d-\x0d\x0d")
_, _ = plugin.ParseDefinition(data)
// panic: runtime error: hash of unhashable type []interface {} [recovered]
}

func main() {
repro_ParseDefinition()
}

// Run with:
// go run main.go
```

STEP 4: Execute the program with: `go run main.go`

## Supporting Material/References:

This testing program will crash with the following error message:

``` sh
panic: runtime error: hash of unhashable type []interface {} [recovered]
panic: runtime error: hash of unhashable type []interface {}

goroutine 1 [running]:
github.com/buildkite/yaml.handleErr(0xc0001aff00)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/yaml.go:249 +0x85
panic(0x5f5f80, 0xc000013840)
/usr/lib/go-1.15/src/runtime/panic.go:969 +0x175
github.com/buildkite/yaml.(*decoder).mappingSlice(0xc00007a540, 0xc00018c7e0, 0x5ee400, 0xc00000e5e0, 0x197, 0x0)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/decode.go:672 +0x806
github.com/buildkite/yaml.(*decoder).mapping(0xc00007a540, 0xc00018c7e0, 0x5ee400, 0xc00000e5e0, 0x197, 0x5ee400)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/decode.go:575 +0xac5
github.com/buildkite/yaml.(*decoder).unmarshal(0xc00007a540, 0xc00018c7e0, 0x5ee400, 0xc00000e5e0, 0x197, 0xc00018c7e0)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/decode.go:328 +0x133
github.com/buildkite/yaml.(*decoder).document(0xc00007a540, 0xc00018c770, 0x5ee400, 0xc00000e5e0, 0x197, 0x600)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/decode.go:340 +0x7c
github.com/buildkite/yaml.(*decoder).unmarshal(0xc00007a540, 0xc00018c770, 0x5ee400, 0xc00000e5e0, 0x197, 0x197)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/decode.go:316 +0x1c5
github.com/buildkite/yaml.unmarshal(0xc00001a820, 0x1d, 0x1d, 0x5e16a0, 0xc00000e5e0, 0x629e00, 0x0, 0x0)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/yaml.go:148 +0x34f
github.com/buildkite/yaml.Unmarshal(...)
/home/pat/go/pkg/mod/github.com/buildkite/yaml@v0.0.0-20181016232759-0caa5f0796e3/yaml.go:81
github.com/buildkite/agent/agent/plugin.ParseDefinition(0xc00001a820, 0x1d, 0x1d, 0x0, 0xffffffff, 0xc000018118)
/XXX/agent/agent/plugin/definition.go:31 +0x79
main.repro_ParseDefinition(...)
/XXX/agent/crashParseDefinition/main.go:9
main.main()
/XXX/agent/crashParseDefinition/main.go:14 +0x88
exit status 2

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.