diff --git a/release_build_files/readme.md b/release_build_files/readme.md index 4c99e1ee91..88a694eae6 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -618,6 +618,8 @@ code. - General (Desktop): Fixed Auth and App Check staying registered with their `App` after being deleted. Previously a deleted `AppCheck` instance could be silently re-created by other products using the same `App`. + - Storage (Desktop): Fixed a crash when destroying a `Listener` that was + never passed to a storage operation. ### 14.2.0 - Changes diff --git a/storage/src/desktop/listener_desktop.cc b/storage/src/desktop/listener_desktop.cc index 30dfd0ccfe..14ddcd8f7a 100644 --- a/storage/src/desktop/listener_desktop.cc +++ b/storage/src/desktop/listener_desktop.cc @@ -25,7 +25,10 @@ namespace storage { namespace internal { ListenerInternal::ListenerInternal(Listener *listener) - : listener_(listener), bytes_transferred_(-1), total_byte_count_(-1) {} + : listener_(listener), + rest_operation_(nullptr), + bytes_transferred_(-1), + total_byte_count_(-1) {} ListenerInternal::~ListenerInternal() { MutexLock lock(mutex_); diff --git a/storage/tests/CMakeLists.txt b/storage/tests/CMakeLists.txt index d4ec18d6a0..65b27e50e6 100644 --- a/storage/tests/CMakeLists.txt +++ b/storage/tests/CMakeLists.txt @@ -23,3 +23,11 @@ firebase_cpp_cc_test( firebase_testing ) +firebase_cpp_cc_test( + firebase_storage_desktop_listener_test + SOURCES + desktop/listener_desktop_test.cc + DEPENDS + firebase_rest_lib + firebase_storage +) diff --git a/storage/tests/desktop/listener_desktop_test.cc b/storage/tests/desktop/listener_desktop_test.cc new file mode 100644 index 0000000000..367d924fa7 --- /dev/null +++ b/storage/tests/desktop/listener_desktop_test.cc @@ -0,0 +1,39 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "storage/src/desktop/listener_desktop.h" + +#include +#include + +#include "gtest/gtest.h" + +namespace { + +using firebase::storage::internal::ListenerInternal; + +// Regression test for https://github.com/firebase/firebase-cpp-sdk/issues/1966. +// A listener that was never attached to an operation must not touch a rest +// operation when it is destroyed. The object is constructed in pre-filled +// storage so that any member the constructor leaves uninitialized holds a +// non-null garbage value. +TEST(ListenerDesktopTest, DestroyWithoutAttachedOperation) { + alignas(ListenerInternal) unsigned char storage[sizeof(ListenerInternal)]; + std::memset(storage, 0xAB, sizeof(storage)); + + ListenerInternal* listener = new (storage) ListenerInternal(nullptr); + listener->~ListenerInternal(); +} + +} // namespace