Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory allocation issue caused by ABI compatibility problem for dynamic proto library #16817

Open
GabrielDracula opened this issue May 10, 2024 · 0 comments
Labels
untriaged auto added to all issues by default when created.

Comments

@GabrielDracula
Copy link

GabrielDracula commented May 10, 2024

Hello, I got a problem about memory allocation when I test ABI compatibility of dynamic proto library.
What version of protobuf and what language are you using?
Version: v3.19.6
Language: C++

What operating system (Linux, Windows, ...) and version?
Linux Ubuntu 20.04.6

What runtime / compiler are you using (e.g., python version or gcc version)
gcc 9.4.0

What did you do?
I make a program to test ABI compatibility of proto dynamic library.
This program is constructed with MessageClass(which is defined by proto), Class1, Class2, some communication class and entry main. In this program, I make Class1 object to create a MessageClass object and transform to Class2 object.
The MessageClass consists of two fields, version and message, both of which are of type string.
I make three dynamic libraries for Class1, Class2 and MessageClass. Class1 and Class2 depends on MessageClass.

When I run the program as usual, there is no problem. However, the following are the actions that cause the problem:

  1. Build the program and copy Class1 library for backup.
  2. Add a test field at the last of MessageClass in *.proto file(its field number is larger than other field), and then build the program without modifying other parts.
  3. Replace new Class1 library with backup library.
  4. Run program.

What did you expect to see
I think it should run as if I have not replaced Class1 library.

What did you see instead?
A coredump happened. It shows malloc(): invalid size (unsorted) when running the code defined in Class1.

We use gdb to find error location, and find that errors may occur in different positions, but they must occur during memory allocation. When I define an additional std::string object with over 16 length in member function of Class1 , or set message field of MessageClass object, it will crash when allocate more memory. However, the program is little enough and do not need much memory.

I tried to define a MessageClass in usual way instead of using proto, and performed the above actions that may result in errors. The program runs normally. So I think it may be a feature or bug of dynamic proto library which limits memory allocation.

Anything else we should know about your project / environment
I use bazel 6.5.0 in this program, and use cc_shared_library wrapped with cc_import to build and dynamically link these dynamic libraries.

@GabrielDracula GabrielDracula added the untriaged auto added to all issues by default when created. label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged auto added to all issues by default when created.
Projects
None yet
Development

No branches or pull requests

1 participant