From 5100be2b7746391c2724e2793e1428c36b63c98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20R=C3=B6hling?= Date: Mon, 16 Dec 2019 16:21:41 +0100 Subject: [PATCH] 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 --- python/google/protobuf/pyext/unknown_fields.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index 7f4fb23edf..5dbcd88568 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc @@ -274,13 +274,13 @@ static PyObject* GetData(PyUnknownFieldRef* self, void *closure) { 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(),