Prevent integer overflow for unknown fields The PyInt_FromLong() conversion function will truncate 64 bit integer values on 32 bit architectures. We will now use the PyLong_* functions with the appropriate minimum size for each field. Note that this commit also switches to the unsigned versions, since the unknown integer fields have been declared unsigned anyway. Fixes #6205
diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index 7f4fb23..5dbcd88 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc
@@ -274,13 +274,13 @@ PyObject* data = NULL; switch (field->type()) { case UnknownField::TYPE_VARINT: - data = PyLong_FromLong(field->varint()); + data = PyLong_FromUnsignedLongLong(field->varint()); break; case UnknownField::TYPE_FIXED32: - data = PyLong_FromLong(field->fixed32()); + data = PyLong_FromUnsignedLong(field->fixed32()); break; case UnknownField::TYPE_FIXED64: - data = PyLong_FromLong(field->fixed64()); + data = PyLong_FromUnsignedLongLong(field->fixed64()); break; case UnknownField::TYPE_LENGTH_DELIMITED: data = PyBytes_FromStringAndSize(field->length_delimited().data(),