From 585a8f19fa7736b3fadffd5d52a426934d320972 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 29 Apr 2020 22:54:33 +0300 Subject: [PATCH] Fix total UserPhotos count if know more photos than expected. GitOrigin-RevId: ff30c4e2d6965d02eb24a9d58b1f01ea1d3d89a7 --- td/telegram/ContactsManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index fa3fc6297..8b66e2e32 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8905,6 +8905,14 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim user_photos->photos.push_back(std::move(user_photo)); add_user_photo_id(u, user_id, user_photos->photos.back().id, photo_get_file_ids(user_photos->photos.back())); } + + auto known_photo_count = narrow_cast(user_photos->photos.size()); + CHECK(user_photos->count >= known_photo_count); + if (user_photos->offset + known_photo_count > user_photos->count) { + LOG(ERROR) << "Fix total photo count of " << user_id << " from " << user_photos->count << " to " + << user_photos->offset << " + " << known_photo_count; + user_photos->count = user_photos->offset + known_photo_count; + } } bool ContactsManager::on_update_bot_info(tl_object_ptr &&new_bot_info, bool send_update) {