Skip to content

Commit a50899c

Browse files
laramielcopybara-github
authored andcommitted
Return false when C++ protos have different DescriptorPools.
PiperOrigin-RevId: 486118277
1 parent 158cc03 commit a50899c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pybind11_protobuf/proto_cast_util.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,13 @@ absl::optional<std::string> PyProtoDescriptorName(py::handle py_proto) {
584584

585585
bool PyProtoIsCompatible(py::handle py_proto, const Descriptor* descriptor) {
586586
assert(PyGILState_Check());
587-
assert(descriptor->file()->pool() == DescriptorPool::generated_pool());
587+
if (descriptor->file()->pool() != DescriptorPool::generated_pool()) {
588+
/// This indicates that the C++ descriptor does not come from the C++
589+
/// DescriptorPool. This may happen if the C++ code has the same proto
590+
/// in different descriptor pools, perhaps from different shared objects,
591+
/// and could be result in undefined behavior.
592+
return false;
593+
}
588594

589595
auto py_descriptor = ResolveAttrs(py_proto, {"DESCRIPTOR"});
590596
if (!py_descriptor) {

0 commit comments

Comments
 (0)