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

Panics on truncated input #20

Open
tv42 opened this issue Jul 5, 2018 · 1 comment
Open

Panics on truncated input #20

tv42 opened this issue Jul 5, 2018 · 1 comment

Comments

@tv42
Copy link

tv42 commented Jul 5, 2018

$ ls
gencode.schema  main.go
$ cat main.go 
package main

//go:generate gencode go -schema gencode.schema

func main() {
	var x Foo
	x.Unmarshal([]byte{})
}
$ cat gencode.schema 
struct Foo {
  Bar byte
}
$ go generate
$ go run main.go gencode.schema.gen.go 
panic: runtime error: index out of range

goroutine 1 [running]:
main.(*Foo).Unmarshal(...)
	/home/tv/go/src/eagain.net/2018/gencode-bug/gencode.schema.gen.go:45
main.main()
	/home/tv/go/src/eagain.net/2018/gencode-bug/main.go:7 +0x11
exit status 2
$ 
@Elojah
Copy link

Elojah commented Jul 9, 2018

Had the same issue when internally mismatching schemas. Could be ok for internal use but over network this is deal breaker...
Size checking should slow marshal/unmarshal ops so having a -safe option to generate not-panickable code could be great to keep performances where needed

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

No branches or pull requests

2 participants