2
2
3
3
#include < Python.h>
4
4
5
+ #include < climits>
5
6
#include < memory>
6
7
#include < string>
7
8
@@ -38,7 +39,7 @@ PythonMessageMutator::~PythonMessageMutator() {
38
39
// check.
39
40
if (!PyErr_Occurred () && owned_msg_ != nullptr ) {
40
41
std::string wire;
41
- message_->SerializeToString (&wire);
42
+ message_->SerializePartialToString (&wire);
42
43
PyObject* py_wire = PyBytes_FromStringAndSize (
43
44
wire.data (), static_cast <Py_ssize_t>(wire.size ()));
44
45
PyObject* parse =
@@ -81,8 +82,14 @@ bool PythonConstMessagePointer::NotChanged() {
81
82
return false ;
82
83
}
83
84
85
+ // Skip the check if too large. Parse won't work
86
+ // for messages larger than 2 GB.
87
+ if (message_->ByteSizeLong () > INT_MAX) {
88
+ return true ;
89
+ }
90
+
84
91
PyObject* py_serialized_pb (
85
- PyObject_CallMethod (py_msg_, " SerializeToString " , nullptr ));
92
+ PyObject_CallMethod (py_msg_, " SerializePartialToString " , nullptr ));
86
93
if (py_serialized_pb == nullptr ) {
87
94
PyErr_Format (PyExc_ValueError, " Fail to serialize py_msg" );
88
95
return false ;
@@ -99,19 +106,19 @@ bool PythonConstMessagePointer::NotChanged() {
99
106
// serialize result may still diff between languages. So parse to
100
107
// another c++ message for compare.
101
108
std::unique_ptr<google::protobuf::Message> parsed_msg (owned_msg_->New ());
102
- parsed_msg->ParseFromArray (data, static_cast <int >(len));
109
+ parsed_msg->ParsePartialFromArray (data, static_cast <int >(len));
103
110
std::string wire_other;
104
111
google::protobuf::io::StringOutputStream stream_other (&wire_other);
105
112
google::protobuf::io::CodedOutputStream output_other (&stream_other);
106
113
output_other.SetSerializationDeterministic (true );
107
- parsed_msg->SerializeToCodedStream (&output_other);
114
+ parsed_msg->SerializePartialToCodedStream (&output_other);
108
115
output_other.Trim ();
109
116
110
117
std::string wire;
111
118
google::protobuf::io::StringOutputStream stream (&wire);
112
119
google::protobuf::io::CodedOutputStream output (&stream);
113
120
output.SetSerializationDeterministic (true );
114
- owned_msg_->SerializeToCodedStream (&output);
121
+ owned_msg_->SerializePartialToCodedStream (&output);
115
122
output.Trim ();
116
123
117
124
if (wire == wire_other) {
0 commit comments