summaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/protobuf/proto/decode.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/protobuf/proto/decode.go')
-rw-r--r--vendor/google.golang.org/protobuf/proto/decode.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/vendor/google.golang.org/protobuf/proto/decode.go b/vendor/google.golang.org/protobuf/proto/decode.go
index 42fc5195e..49f9b8c88 100644
--- a/vendor/google.golang.org/protobuf/proto/decode.go
+++ b/vendor/google.golang.org/protobuf/proto/decode.go
@@ -45,12 +45,14 @@ type UnmarshalOptions struct {
}
// Unmarshal parses the wire-format message in b and places the result in m.
+// The provided message must be mutable (e.g., a non-nil pointer to a message).
func Unmarshal(b []byte, m Message) error {
_, err := UnmarshalOptions{}.unmarshal(b, m.ProtoReflect())
return err
}
// Unmarshal parses the wire-format message in b and places the result in m.
+// The provided message must be mutable (e.g., a non-nil pointer to a message).
func (o UnmarshalOptions) Unmarshal(b []byte, m Message) error {
_, err := o.unmarshal(b, m.ProtoReflect())
return err
@@ -116,10 +118,10 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
// Parse the tag (field number and wire type).
num, wtyp, tagLen := protowire.ConsumeTag(b)
if tagLen < 0 {
- return protowire.ParseError(tagLen)
+ return errDecode
}
if num > protowire.MaxValidNumber {
- return errors.New("invalid field number")
+ return errDecode
}
// Find the field descriptor for this field number.
@@ -159,7 +161,7 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
}
valLen = protowire.ConsumeFieldValue(num, wtyp, b[tagLen:])
if valLen < 0 {
- return protowire.ParseError(valLen)
+ return errDecode
}
if !o.DiscardUnknown {
m.SetUnknown(append(m.GetUnknown(), b[:tagLen+valLen]...))
@@ -194,7 +196,7 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
}
b, n = protowire.ConsumeBytes(b)
if n < 0 {
- return 0, protowire.ParseError(n)
+ return 0, errDecode
}
var (
keyField = fd.MapKey()
@@ -213,10 +215,10 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
for len(b) > 0 {
num, wtyp, n := protowire.ConsumeTag(b)
if n < 0 {
- return 0, protowire.ParseError(n)
+ return 0, errDecode
}
if num > protowire.MaxValidNumber {
- return 0, errors.New("invalid field number")
+ return 0, errDecode
}
b = b[n:]
err = errUnknown
@@ -246,7 +248,7 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
if err == errUnknown {
n = protowire.ConsumeFieldValue(num, wtyp, b)
if n < 0 {
- return 0, protowire.ParseError(n)
+ return 0, errDecode
}
} else if err != nil {
return 0, err
@@ -272,3 +274,5 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
// to the unknown field set of a message. It is never returned from an exported
// function.
var errUnknown = errors.New("BUG: internal error (unknown)")
+
+var errDecode = errors.New("cannot parse invalid wire-format data")