goprotobuf: Fix a couple of instances where bad input could cause a panic.
R=r
CC=golang-dev
http://codereview.appspot.com/5554045
diff --git a/proto/decode.go b/proto/decode.go
index f84d571..b2a27b9 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -181,9 +181,11 @@
}
nb := int(n)
+ if nb < 0 {
+ return nil, fmt.Errorf("proto: bad byte length %d", nb)
+ }
if p.index+nb > len(p.buf) {
- err = io.ErrUnexpectedEOF
- return
+ return nil, io.ErrUnexpectedEOF
}
if !alloc {
@@ -279,7 +281,7 @@
}
}
default:
- fmt.Fprintf(os.Stderr, "proto: can't skip wire type %d for %s\n", wire, t)
+ err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t)
}
return err
}