Skip to content

Commit

Permalink
Fix a Python extension crash in the descriptor's nested types contain…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeldelalleau authored and anandolee committed Jul 31, 2019
1 parent f38b6ed commit 5db5c26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/google/protobuf/internal/descriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ def testCppDescriptorContainer_Iterator(self):
del enum
self.assertEqual('FOO', next(values_iter).name)

def testDescriptorNestedTypesContainer(self):
message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
nested_message_descriptor = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR
self.assertEqual(len(message_descriptor.nested_types), 3)
self.assertFalse(None in message_descriptor.nested_types)
self.assertTrue(nested_message_descriptor in message_descriptor.nested_types)

def testServiceDescriptor(self):
service_descriptor = unittest_pb2.DESCRIPTOR.services_by_name['TestService']
self.assertEqual(service_descriptor.name, 'TestService')
Expand Down
1 change: 1 addition & 0 deletions python/google/protobuf/pyext/descriptor_containers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ int Find(PyContainer* self, PyObject* item) {
// the .proto file definition.
const void* descriptor_ptr = PyDescriptor_AsVoidPtr(item);
if (descriptor_ptr == NULL) {
PyErr_Clear();
// Not a descriptor, it cannot be in the list.
return -1;
}
Expand Down

0 comments on commit 5db5c26

Please sign in to comment.