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

protoparse: panic when parsing empty file #192

Closed
bradleyjkemp opened this issue May 5, 2019 · 1 comment · Fixed by #195
Closed

protoparse: panic when parsing empty file #192

bradleyjkemp opened this issue May 5, 2019 · 1 comment · Fixed by #195

Comments

@bradleyjkemp
Copy link

Hi, found this panic when trying to parse an empty file. The error seems to be in github.com/jhump/protoreflect/desc/protoparse/parser.go:559 where lx.err is nil so no error is returned but lx.res is also nil so a nil pointer dereference occurs later when this is accessed.

To reproduce just try to parse any empty file or use the following self-contained example:

package main

import (
	"bytes"
	"io"
	"io/ioutil"

	"github.com/jhump/protoreflect/desc/protoparse"
)

func main() {
	protoparse.Parser{
		Accessor: func(filename string) (io.ReadCloser, error) {
			return ioutil.NopCloser(bytes.NewBuffer(nil)), nil
		},
	}.ParseFiles("this_crashes.proto")
}

Stack trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x1243e81]

goroutine 1 [running]:
github.com/jhump/protoreflect/desc/protoparse.(*parseResult).createFileDescriptor(0xc00000acc0, 0x130cc9e, 0xa, 0x0, 0x134cf60, 0xc000022c00)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:597 +0x151
github.com/jhump/protoreflect/desc/protoparse.createParseResult(0x130cc9e, 0xa, 0x0, 0x1672048, 0xc0000b5b20, 0xc0000b5b18)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:588 +0xb4
github.com/jhump/protoreflect/desc/protoparse.parseProto(0x130cc9e, 0xa, 0x1672048, 0xc0001179e0, 0xc000117900, 0x0, 0x200000, 0x4220000)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:571 +0x1fd
github.com/jhump/protoreflect/desc/protoparse.parseProtoFiles.func1(0x134d0e0, 0xc0001179e0, 0xc0000b5c00, 0xc000117900, 0xc0000b5ce8, 0xc0000b5c10)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:383 +0xd9
github.com/jhump/protoreflect/desc/protoparse.parseProtoFiles(0xc0000752c0, 0xc0000b5e68, 0x1, 0x1, 0xc0000a0000, 0xc0000b5ce8, 0x1550ea0, 0xc000000300)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:384 +0x3af
github.com/jhump/protoreflect/desc/protoparse.Parser.ParseFilesButDoNotLink(0x0, 0x0, 0x0, 0x0, 0xc0000752c0, 0x0, 0xc0000b5e68, 0x1, 0x1, 0x12ac2a0, ...)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/parser.go:237 +0x13c
github.com/jhump/protoreflect/desc/protoparse.Fuzz(0x4220000, 0x0, 0x200000, 0x4)
	$GOPATH/src/github.com/jhump/protoreflect/desc/protoparse/fuzz.go:20 +0x151
go-fuzz-dep.Main(0xc0000b5f80, 0x1, 0x1)
	/var/folders/6m/r713l1xj6_dcykbx21svs09h0000gp/T/go-fuzz-build315933473/goroot/src/go-fuzz-dep/main.go:36 +0x1b6
main.main()
	/var/folders/6m/r713l1xj6_dcykbx21svs09h0000gp/T/go-fuzz-build315933473/gopath/src/github.com/jhump/protoreflect/desc/protoparse/go.fuzz.main/main.go:15 +0x52
exit status 2

(I also created a simple fuzzing harness for both ParseFiles and ParseFilesButDoNotLink but go-fuzz didn't find any other panics so far)

@jhump
Copy link
Owner

jhump commented May 6, 2019

Thanks for the report, @bradleyjkemp!

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