internal/impl: fix unmarshal of group containing their own field number
The fast-path unmarshal was getting confused when parsing a group
containing a field with a number the same as the group's own field
number. Separate the handling of EndGroup tags.
Change-Id: I637702b42c94a26102e693ee29a55e80b37d7f28
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/214737
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/internal/impl/decode.go b/internal/impl/decode.go
index e48081e..5bce77a 100644
--- a/internal/impl/decode.go
+++ b/internal/impl/decode.go
@@ -90,6 +90,13 @@
}
b = b[n:]
+ if wtyp == wire.EndGroupType {
+ if num != groupTag {
+ return 0, errors.New("mismatching end group marker")
+ }
+ return start - len(b), nil
+ }
+
var f *coderFieldInfo
if int(num) < len(mi.denseCoderFields) {
f = mi.denseCoderFields[num]
@@ -103,9 +110,6 @@
break
}
n, err = f.funcs.unmarshal(b, p.Apply(f.offset), wtyp, opts)
- case num == groupTag && wtyp == wire.EndGroupType:
- // End of group.
- return start - len(b), nil
default:
// Possible extension.
if exts == nil && mi.extensionOffset.IsValid() {