Skip to content

Different values of EnableCustomNew cause crashes #21312

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

Open
netheril96 opened this issue Apr 16, 2025 · 1 comment
Open

Different values of EnableCustomNew cause crashes #21312

netheril96 opened this issue Apr 16, 2025 · 1 comment
Labels

Comments

@netheril96
Copy link

What version of protobuf and what language are you using?
Version: main
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows & Mac

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

What did you do?

Several related:

The key problem is that the libprotobuf and the protobuf generated code are built by different compilers. In the first case, libprotobuf is built by MSVC and the generated code by clang-cl 19. In the second case, libprotobuf is built by an older version of clang and the generated code by a newer version.

In both cases, the compiler for the generated code has support for __is_bitwise_cloneable, and therefore EnableCustomNew is true. The generated code then creates MessageCreator with func == nullptr (here).. But the library is built by a compiler without such functionality, and because of that, this is always true, and it blindly dereferences a null pointer func even though tag is not kFunc, causing SIGSEGV.

What did you expect to see

Library and generated code can be built by different compilers and linked together as long as they are ABI compatible.

Although inside Google everything is always built together by the same compiler, the outside world expects differently. In the world outside Google, libprotobuf is usually provided by a package manager rather than built together as the consumer source code, so compiler version match is widely present.

What did you see instead?

When the generated code is built by a newer version of compiler, the linked binary may crash with SIGSEGV.

Anything else we should know about your project / environment

@netheril96 netheril96 added the untriaged auto added to all issues by default when created. label Apr 16, 2025
@shaod2 shaod2 added c++ and removed untriaged auto added to all issues by default when created. labels Apr 16, 2025
@shaod2
Copy link
Member

shaod2 commented Apr 16, 2025

This looks a bit worrying per the last paragraph from https://protobuf.dev/support/cross-version-runtime-guarantee/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants