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

plugin: yaml library panics when used from plugin #18979

Closed
owbone opened this issue Feb 7, 2017 · 2 comments
Closed

plugin: yaml library panics when used from plugin #18979

owbone opened this issue Feb 7, 2017 · 2 comments
Milestone

Comments

@owbone
Copy link

owbone commented Feb 7, 2017

I have already raised this with the yaml library here, hoping to narrow down the issue, but unfortunately the project doesn't seem to be terribly active. However I don't see how this problem could be the fault of the library.

What version of Go are you using (go version)?

go version go1.8rc3 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/oliver/workspace"
GORACE=""
GOROOT="/nix/store/nz3j87ls421358ks5bd24dgq9c8z59sn-go-1.8-dev/share/go"
GOTOOLDIR="/nix/store/nz3j87ls421358ks5bd24dgq9c8z59sn-go-1.8-dev/share/go/pkg/tool/linux_amd64"
GCCGO="/nix/store/jm8nf0p2n6m092385kmb87zxhanxigvc-gccgo49-wrapper-4.9.4/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/run/user/1000/go-build507203162=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

// main.go
package main

import "plugin"
import "gopkg.in/yaml.v2"

func main() {
	var baz map[string]string
	yaml.Unmarshal([]byte("foo: bar"), &baz)

	handle, _ := plugin.Open("plugin.so")
	symbol, _ := handle.Lookup("Go")
	symbol.(func())()
}
// plugin.go
package main

import "gopkg.in/yaml.v2"

func Go() {
	var baz map[string]string
	yaml.Unmarshal([]byte("foo: bar"), &baz)
}
# Makefile
build: clean
	@go build -buildmode=plugin -o plugin.so plugin.go
	@go build -o main main.go

clean:
	@rm -rf main *.so

Build and run the executable with make && ./main.

What did you expect to see?

The program should complete successfully.

What did you see instead?

The following panic:

panic: expected end of document event but got 7 [recovered]
	panic: expected end of document event but got 7

goroutine 1 [running]:
plugin/vendor/gopkg.in/yaml%2ev2.handleErr(0xc420053ed8)
	/home/oliver/workspace/src/plugin/vendor/gopkg.in/yaml.v2/yaml.go:153 +0x95
panic(0x5a0c80, 0xc4200106e0)
	/nix/store/nz3j87ls421358ks5bd24dgq9c8z59sn-go-1.8-dev/share/go/src/runtime/panic.go:489 +0x2e7
plugin/vendor/gopkg.in/yaml%2ev2.(*parser).document(0xc4200be000, 0x7f24b3c8a144)
	/home/oliver/workspace/src/plugin/vendor/gopkg.in/yaml.v2/decode.go:141 +0x203
plugin/vendor/gopkg.in/yaml%2ev2.(*parser).parse(0xc4200be000, 0x5d3ce8)
	/home/oliver/workspace/src/plugin/vendor/gopkg.in/yaml.v2/decode.go:116 +0x100
plugin/vendor/gopkg.in/yaml%2ev2.Unmarshal(0xc4200106a0, 0x8, 0x8, 0x59a360, 0xc4200ac6c8, 0x0, 0x0)
	/home/oliver/workspace/src/plugin/vendor/gopkg.in/yaml.v2/yaml.go:84 +0x177
plugin/unnamed-8517ae4ac6807292a59c508315fef6ff06256b82.Go()
	/home/oliver/workspace/src/plugin/plugin.go:7 +0x9e
main.main()
	/home/oliver/workspace/src/plugin/main.go:9 +0xaa

The ordering of the yaml.Unmarshal() calls between the executable and the plugin doesn't seem to matter, but it does have to be called from both.

Tracing through the code, it seems that the plugin takes a completely different (and wrong) codepath when provided with the same input, and at certain points it changes when adding a simple fmt.Printf().

@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Feb 7, 2017
@tzneal
Copy link
Member

tzneal commented Apr 13, 2017

I can reproduce this with 1.8, but not with tip. One of the recent plugin fixes might have resolved it, can you verify?

@tzneal
Copy link
Member

tzneal commented May 3, 2017

Confirmed fixed on tip.

@tzneal tzneal closed this as completed May 3, 2017
@golang golang locked and limited conversation to collaborators May 3, 2018
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

5 participants