[protobuf] Solved: Invalid file descriptor data passed to EncodedDescriptorDatabase::Add()

I’ll make this brief, but wanted to document my fix to potentially save someone else some aggravation in the future.

I’ve been working on a c++ project utilizing Google protobuf, and at one point ran into an error during application startup (static initialization):

libprotobuf ERROR google/protobuf/descriptor_database.cc:314] Invalid file descriptor data passed to EncodedDescriptorDatabase::Add().
libprotobuf FATAL google/protobuf/descriptor.cc:862] CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
Abort (core dumped)

I came across two bug reports against protobuf that experienced this same error, but they seemed to be related to charset conversions. (This was briefly a red herring for me, since I had run into a charset issue earlier the same day, but didn’t end up solving my problem.)

Stepping through the code with a debugger alerted me to where in the code the abort signal was being thrown: from a call to ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(…) with a big hard-coded string inside the pb.cc (protobuf-generated) file. This was my Eureka! moment, since I saw the filename of the original .proto file in the hard-coded string, which reminded me that at one point I’d renamed my .proto file and message name with ‘rename’ and ‘sed,’ and while the compiler thought everything was ok, apparently that wasn’t enough for protobuf.

Solution

After see that filename and remember the change I’d made, I just re-ran protoc ––cpp-out=./ <message.proto>, recompiled, and voilà, I was able to run without error! (Note that –cpp_out should use two standard hyphens; WordPress likes to be too smart for itself and replace characters with fancier versions, and I don’t want to patch core files on my shared system to fix it.)

Tags: , ,

2 Responses to “[protobuf] Solved: Invalid file descriptor data passed to EncodedDescriptorDatabase::Add()”

  1. Jean-Phi Says:

    Thanks a lot for your description it helped me a lot. I has notice this big string but did not look at it at all … somehow one of my proto files is not running properly but I least now my App starts :-)

  2. sunil Says:

    Hi,
    I have same problem like you mentioned. But, PB.* Files generated on linux and i am using on QNX OS. On my QNX, i have protobuf library but dont have protoc on QNX to generate PB files, so using files which generated by Linux. Is it ok use?

    Thanks&regards,
    Sunilkumar K

Leave a Reply