From 7b0be02503f04dc1aa347e77d3284188a72d4d3b Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 6 Jun 2019 18:09:48 +0300 Subject: [PATCH] Copy BufferSlice before saving user profile photo. GitOrigin-RevId: f4a4e8dcae1eeea6d8111705d3cd4fbaaa805bf4 --- td/telegram/ContactsManager.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a74654c19..cbe3d6b22 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6909,6 +6909,19 @@ void ContactsManager::on_update_user_photo(User *u, UserId user_id, tl_object_ptr &&photo) { if (td_->auth_manager_->is_bot() && !G()->parameters().use_file_db && !u->is_photo_inited) { bool is_empty = photo == nullptr || photo->get_id() == telegram_api::userProfilePhotoEmpty::ID; + if (!is_empty) { + CHECK(photo->get_id() == telegram_api::userProfilePhoto::ID); + auto user_photo = static_cast(photo.get()); + + auto copy_location = [](telegram_api::FileLocation *location_ptr) { + if (location_ptr->get_id() == telegram_api::fileLocation::ID) { + auto location = static_cast(location_ptr); + location->file_reference_ = location->file_reference_.copy(); + } + }; + copy_location(user_photo->photo_small_.get()); + copy_location(user_photo->photo_big_.get()); + } pending_user_photos_[user_id] = std::move(photo); UserFull *user_full = get_user_full(user_id);