proto: validate UTF-8 in proto3 strings
Change-Id: I6a495730c3f438e7b2c4ca86edade7d6f25aa47d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/171700
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/encoding/jsonpb/decode_test.go b/encoding/jsonpb/decode_test.go
index 941e416..cb99bcd 100644
--- a/encoding/jsonpb/decode_test.go
+++ b/encoding/jsonpb/decode_test.go
@@ -5,6 +5,7 @@
package jsonpb_test
import (
+ "bytes"
"math"
"testing"
@@ -2130,14 +2131,14 @@
"value": "` + "abc\xff" + `"
}`,
wantMessage: func() proto.Message {
- m := &knownpb.StringValue{Value: "abc\xff"}
+ m := &knownpb.StringValue{Value: "abcd"}
b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m)
if err != nil {
t.Fatalf("error in binary marshaling message for Any.value: %v", err)
}
return &knownpb.Any{
TypeUrl: "google.protobuf.StringValue",
- Value: b,
+ Value: bytes.Replace(b, []byte("abcd"), []byte("abc\xff"), -1),
}
}(),
wantErr: true,
@@ -2216,14 +2217,14 @@
"value": "` + "abc\xff" + `"
}`,
wantMessage: func() proto.Message {
- m := &knownpb.Value{Kind: &knownpb.Value_StringValue{"abc\xff"}}
+ m := &knownpb.Value{Kind: &knownpb.Value_StringValue{"abcd"}}
b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m)
if err != nil {
t.Fatalf("error in binary marshaling message for Any.value: %v", err)
}
return &knownpb.Any{
TypeUrl: "google.protobuf.Value",
- Value: b,
+ Value: bytes.Replace(b, []byte("abcd"), []byte("abc\xff"), -1),
}
}(),
wantErr: true,
@@ -2369,7 +2370,7 @@
}
}`,
wantMessage: func() proto.Message {
- m1 := &knownpb.StringValue{Value: "abc\xff"}
+ m1 := &knownpb.StringValue{Value: "abcd"}
b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m1)
if err != nil {
t.Fatalf("error in binary marshaling message for Any.value: %v", err)
@@ -2385,7 +2386,7 @@
}
return &knownpb.Any{
TypeUrl: "pb2.KnownTypes",
- Value: b,
+ Value: bytes.Replace(b, []byte("abcd"), []byte("abc\xff"), -1),
}
}(),
wantErr: true,