goprotobuf: Better error handling for invalid input that mentions tag 0.
R=r
CC=golang-dev
http://codereview.appspot.com/5653064
diff --git a/proto/decode.go b/proto/decode.go
index 66f7a05..836227e 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -348,6 +348,9 @@
return ErrWrongType
}
tag := int(u >> 3)
+ if tag <= 0 {
+ return fmt.Errorf("proto: illegal tag %d", tag)
+ }
fieldnum, ok := prop.tags[tag]
if !ok {
// Maybe it's an extension?
@@ -365,7 +368,7 @@
p := prop.Prop[fieldnum]
if p.dec == nil {
- fmt.Fprintf(os.Stderr, "no protobuf decoder for %s.%s\n", t, st.Field(fieldnum).Name)
+ fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", t, st.Field(fieldnum).Name)
continue
}
dec := p.dec
diff --git a/proto/properties.go b/proto/properties.go
index 556c177..47bc425 100644
--- a/proto/properties.go
+++ b/proto/properties.go
@@ -443,6 +443,11 @@
prop.tags = make(map[int]int)
prop.origNames = make(map[string]int)
for i, p := range prop.Prop {
+ if strings.HasPrefix(p.Name, "XXX_") {
+ // Internal fields should not appear in tags/origNames maps.
+ // They are handled specially when encoding and decoding.
+ continue
+ }
if p.Required {
reqCount++
}