Fix CFI icall violation in Future callbacks - #1914
Conversation
❌ Integration test FAILEDRequested by @a-maurice on commit 79c2210
Add flaky tests to go/fpl-cpp-flake-tracker |
There was a problem hiding this comment.
Code Review
This pull request refactors the Future<T>::OnCompletion and Future<T>::AddOnCompletion implementations to avoid unsafe reinterpret_cast on callbacks, introducing a typed callback data structure and trampoline functions instead. The review feedback highlights critical safety issues regarding null or empty callbacks: passing a null callback can cause a crash if the future is already completed, and wrapping an empty std::function without validation can trigger a std::bad_function_call exception or crash. Suggestions are provided to handle these cases safely by using dummy callbacks or adding validity checks.
Description
Eliminate unsafe reinterpret_cast of TypedCompletionCallback and std::function completion callbacks to FutureBase::CompletionCallback in Future::OnCompletion and Future::AddOnCompletion.
Introduce type-safe trampoline functions and wrapper data structures (TypedCompletionCallbackTrampoline and TypedCompletionCallbackData) in firebase::detail to bridge the typed callback to the base callback signature expected by ReferenceCountedFutureImpl::RunCallback, avoiding undefined behavior and runtime CFI type check aborts.
Testing
Type of Change
Place an
xthe applicable box:Notes
Release Notessection ofrelease_build_files/readme.md.